通过滑动滑出导航UIView覆盖另一个UIView

在我对这种导航技术的研究中,我发现Nick Harris的这个post是一个很好的开始。 但是,我想要的是与此稍有不同。 你可以把它想象成iOS的Notification Center当你只需要从顶部滑动显示view ,只需滑动回来隐藏它。 在我的情况下,我希望通过向左滑动手势来显示来自屏幕右侧的隐藏UIView ,并通过相同的手势(这次是右侧)再次隐藏它。

我设法得到我以前的post显示/隐藏UIView的解决scheme。 我想补充的一件事是挥动手势。

我不想调整我的应用程序委托来做到这一点,如尼克·哈里斯所做的那样。 所以如果任何人有任何想法/代码样本我怎么能做到这一点,我会很感激。

一些启发 :)

您可以通过向左滑动手势来显示来自屏幕右侧的隐藏的UIView,并通过相同的手势(这次是右侧)再次隐藏它。 添加转换。

在.h文件中添加BOOL didNotSwipe在.m文件中添加其值didNotSwipe = TRUE viewDidLoad方法

用不同的select器向左和向右的方向添加滑动手势到你的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]; } }