2

在我对这种导航技术的研究中,我发现了 Nick Harris 的这篇文章,我想这是一个好的开始。但是,我想要的与此略有不同。Notification Center当您只需要从顶部滑动以显示并向view后滑动以再次隐藏它时,您可以将其视为 iOS 。就我而言,我希望通过UIView向左滑动手势来显示来自屏幕右侧的隐藏,并通过相同的手势再次隐藏它(这次是向右)。

我已经设法在我之前的帖子中找到了一个关于显示/隐藏 UIView 的解决方案。我想添加的一件事是滑动手势。

我不想像 Nick Harris 所做的那样调整我的应用程序委托来执行此操作。因此,如果有人对我如何做到这一点有任何想法/代码示例,我将不胜感激。

一些启发 :)

4

1 回答 1

3

您可以通过向左滑动手势显示来自屏幕右侧的隐藏 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];
   }
 }
于 2012-08-22T04:43:47.187 回答