I have been searching for a way to make a menu come 80 pixels down from the top of the screen and have the screen slide down with it (80 pixels) when the user swipes his finger from top to bottom (and reverse it when they swipe top to bottom to send it back up). How should i go about doing that? Anything helps. Thank you!
Create a UISwipeGestureRecognizer and add it to the view you want it to appear on:
UISwipeGestureRecognizer *swipeGesture = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipe:)];
[swipeGesture setDirection:UISwipeGestureRecognizerDirectionDown];
[self.view addGestureRecognizer:swipeGesture];
Create an instance variable that will hold your menu view and add it to the view OUTSIDE of the screen (note -80 y-coordinate):
menuView = [[UIView alloc] initWithFrame:CGRectMake(0, -80, 320, 80)];
//add whatever controls you need to the menu view, or load it from a nib
[self.view addSubview:menuView];
Define a method that will slide the menu onto the view when down swipe is detected:
-(void)swipe:(UISwipeGestureRecognizer*)sender {
[UIView animateWithDuration:0.5 animations:^{
[menuView setFrame:CGRectMake(0, 0, 320, 80)];
}];
}
If you want the screen to slide down with it or anything else you might like to happen, add additional actions to the animation block.
To remove the view with the upward slide, you can create another UISwipeGestureRecognizer, but with UISwipeGestureRecognizerDirectionUp
direction. Make another method that will do a reverse-slide of the menu.
Hope it helps.