Mega-Gold Problem


#1

Have added this to bottom of initWithFrame:

[code]- (instancetype)initWithFrame:(CGRect)r
{
self = [super initWithFrame:r];

if (self) {

    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self
        action:@selector(swipeUp:)];
    swipeRecognizer.numberOfTouchesRequired = 2;
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionUp;
    swipeRecognizer.delaysTouchesBegan = YES;
    [self addGestureRecognizer:swipeRecognizer];
}
return self;

}[/code]

and this method to BNRDrawView.m

- (void)swipeUp:(UIGestureRecognizer *)gr { NSLog(@"Recognized swipe up"); }

Then I run the application in the iOS Simulator, hold down alt + shift, click the mouse, and drag upward. Every time it draws two lines. Randomly (1 in 100 times), it will call swipeUp:.

I made a UIPinchGestureRecognizer and told it to delayTouchesBegan and to call swipeUp: and it worked every time. Since my code is pretty much exactly the same as others’ who’ve completed this challenge, I can only assume its a bug in the simulator. Can anyone confirm this or correct my code?


#2

So for the silver challenge I modified the gestureRecognizer:shouldRecognizeSimultaneouslyWithGestureRecognizer: method to include the following so that lines would not move unless there had been a long press

- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer { if (gestureRecognizer == self.moveRecognizer && otherGestureRecognizer == self.pressRecognizer) { return YES; } return NO; }

unfortunately, during a swipe, moveRecognizer was also being triggered, but did not have permission to recognize simultaneously until I added this else if statement

else if (gestureRecognizer == self.moveRecognizer && otherGestureRecognizer == self.swipeRecognizer) { return YES; }

I think I could possibly have achieved the same result by overriding gestureRecognizer:shouldRequireFailureOfGestureRecognizer: but it wouldn’t have been any shorter. I appreciate any feedback.