的导航以覆盖另一个

的导航以覆盖另一个

本文介绍了通过滑动滑出 UIView 的导航以覆盖另一个 UIView的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

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

On my research regarding this navigation technique, I've found this post by Nick Harris which is a good start I suppose. However, what I want is slightly different from this. You can think of it as iOS' Notification Center when you just have to swipe from the top to show the view and just swipe back to hide it again. In my case, I wish to reveal a hidden UIView coming from the right side of the screen with a swipe gesture to the left and also hide it again through the same gesture (this time to the right).

我已经在我之前的帖子中找到了解决方案 关于显示/隐藏 UIView.我想补充的一件事是滑动手势.

I've managed to get a solution on my previous post regarding showing/hiding a UIView. One thing I wish to add is the swiping gesture.

我不想像尼克哈里斯那样调整我的应用程序委托来做到这一点.因此,如果有人对我如何做到这一点有任何想法/代码示例,我将不胜感激.

I wouldn't want to tweak my app delegate to do this as Nick Harris has done. So if anyone has any ideas/code samples on how I could do this, I'd be much grateful.

照亮一些:)

推荐答案

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

You can reveal a hidden UIView coming from the right side of the screen with a swipe gesture to the left and also hide it again through the same gesture (this time to the right). adding transition.

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

Add BOOL didNotSwipe in .h file add its value didNotSwipe = TRUE in .m file viewDidLoad method

使用不同的选择器向您的 self.view 添加左右方向的滑动手势.

Add swipe gesture with left and right direction with different selector to your 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];

向左滑动时调用此方法:

When swipe left this method is called:

 -(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];
   }
 }

这篇关于通过滑动滑出 UIView 的导航以覆盖另一个 UIView的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

08-24 03:08