您可以通过向左滑动手势显示来自屏幕右侧的隐藏 UIView,也可以通过相同的手势再次隐藏它(这次是向右)。添加过渡。
在 .h 文件中添加 BOOL didNotSwipe 在 .m 文件 viewDidLoad 方法中添加其值 didNotSwipe = TRUE
将具有不同选择器的左右方向的滑动手势添加到您的 self.view。
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeRight:)];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeleft:)];
[recognizer1 setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer1];
[recognizer1 release];
向左滑动时调用此方法:
-(void)swipeleft:(UISwipeGestureRecognizer *)swipeGesture
{
if (didNotSwipe) {
didNotSwipe = FALSE;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromRight];
[animation setDuration:0.50];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:kCATransition];
[self.view addSubView:self.overlayView];
//[self.overlayView setFrame:CGRectMake(0,0,self.overlayView.frame.size.width,self.overlayView.frame.size.height)];
}
}
向右滑动此方法时:
-(void)swipeRight:(UISwipeGestureRecognizer *)swipeGesture
{
if(!didNotSwipe){
didNotSwipe = TRUE;
CATransition *animation = [CATransition animation];
[animation setDelegate:self];
[animation setType:kCATransitionPush];
[animation setSubtype:kCATransitionFromLeft];
[animation setDuration:0.40];
[animation setTimingFunction:
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]];
[self.view.layer addAnimation:animation forKey:kCATransition];
[self.overlayView removeFromSuperView];
}
}