Mega-Gold Challenge


#1

Nothing about this challenge has been covered in the book so far besides the gesture stuff. Am I seriously missing something? I have no idea where to begin on this…


#2

Not sure if I’m going to try this challenge as (I think) there is no way of implementing the 3 fingered swipe on the iOS simulator.
Maybe this will help though: http://stackoverflow.com/questions/7827860/need-to-delay-touch-for-3-finger-swipe-and-not-1-finger-swipe


#3

@Monkeyboy: why not just use a two-finger swipe? the challenge remains the same


#4

I completed this using the simulator and opted for a new UIViewController subclass that displays a number of buttons, each with a different background colour. I used UIViewController’s presentViewController:animated:completion: and hooked up all the communication between the UIViewControllers and the BNRDrawView.

@jwgraz: Thanks for the suggestion.


#5

Hey guys,

I’ve got it working. First of all you need to handle the gesture. In initWithFrame add:

UISwipeGestureRecognizer *threeFingerSwipe = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(displayPanel:)];
[threeFingerSwipe setDirection:UISwipeGestureRecognizerDirectionUp];
[threeFingerSwipe setNumberOfTouchesRequired:3];
[threeFingerSwipe setDelaysTouchesBegan:YES];
[self addGestureRecognizer:threeFingerSwipe];

Next you need to create a *.xib file. Call it “ColorSelectView”. Mine looks like that:

It’s just five buttons with no text, different backgroundColor. Set the File’s owner to BNRDrawView, create a property

and connect it to the View in *.xib

Now we need to add the view after the swipe gesture, implement the displayPanel method:

-(void)displayPanel:(UIGestureRecognizer *)gr { NSLog(@"swiped up"); CGRect frame = CGRectMake(0, self.window.frame.size.height-50, self.window.frame.size.width, 50); NSLog(@"%@",NSStringFromCGRect(frame)); [[NSBundle mainBundle] loadNibNamed:@"ColorSelectView" owner:self options:nil]; UIView *colorSelect = self.colorView; self.colorView.frame = frame; [self.window addSubview:colorSelect]; [self.window setNeedsDisplay]; }

Now you should add the

to BNRDrawView.m

Next we need to implement the color, so open BNRLine.h and add a property:

No we need the ViewController to draw the lines of selected color, first set up the default color in initWithFrame:

Next modify the touchesEnded method where we create the BNRLine object:

[code]-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
NSLog(@"%@",NSStringFromSelector(_cmd));
for(UITouch *t in touches){
NSValue *key = [NSValue valueWithNonretainedObject:t];
BNRLine *line = self.linesInProgress[key];
line.color = self.selectedColor;
[self.finishedLines addObject:line];
[self.linesInProgress removeObjectForKey:key];
}

[self setNeedsDisplay];

}
[/code]

We need to modify the drawRect method, so it draws back finishedLines with their respective colors:

[code]-(void)drawRect:(CGRect)rect
{
// [self.selectedColor set];
for (BNRLine *line in self.finishedLines)
{
[line.color set];
[self strokeLine:line];
}

if(self.selectedLine){
    [[UIColor greenColor] set];
    [self strokeLine:self.selectedLine];
}

[[UIColor redColor] set];
for(NSValue *key in self.linesInProgress){
    [self strokeLine:self.linesInProgress[key]];
}

}
[/code]

Now connect all the buttons from the *.xib to ONE method:

[code]- (IBAction)colorSelected:(UIButton *)sender {
self.selectedColor = sender.backgroundColor;
[self.colorView removeFromSuperview];

}[/code]

This sets the selectedColor and dismisses the view. And voila, you’re set.


#6

Hey gh0st87,

I was going to do exactly the same thing that you did. But I just cannot make an outlet from the new view with the xib to the DrawView.

this part just doesnt work for me… =(

can you please explain how exactly did you make a connection?

cheers