滑出导航通过刷卡的UIView的叠加另一个的UIView(Slide out navigation

2019-09-21 10:39发布

我的研究有关该导航技术,我发现这个职位由尼克·哈里斯这是一个良好的开端,我想。 不过,我想从这个略有不同。 你可以把它作为iOS的” Notification Center时,你就必须从上面左右滑动来显示view ,只是轻扫回再次隐藏它。 就我而言,我希望揭示隐藏UIView从轻扫手势向左屏幕右侧的到来,也再次隐藏它通过相同的手势(此时在右边)。

我已经成功地得到解决我以前的帖子就显示/隐藏一个UIView。 有一两件事我想补充的是滑动手势。

我不会想调整我的应用程序委托这样做,因为尼克·哈里斯已经完成。 因此,如果任何人有我如何能做到这一点任何想法/代码示例,我会觉得很感激。

一些启发 :)

Answer 1:

你可以揭示一个隐藏的UIView从轻扫手势向左屏幕右侧的到来,也再次隐藏它通过相同的手势(此时在右边)。 加入过渡。

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

添加滑动手势与不同的选择你的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];
   }
 }


文章来源: Slide out navigation through swipes for UIView to overlay another UIView