在我对这种导航技术的研究中,我发现了 this post by Nick Harris我想这是一个好的开始。但是,我想要的与此略有不同。您可以将其视为 iOS 的 Notification Center ,您只需从顶部滑动即可显示 view ,然后只需向后滑动即可再次隐藏它。就我而言,我希望通过向左滑动手势显示来自屏幕右侧的隐藏 UIView 并通过相同的手势再次隐藏它(这次是向右)。
我已经设法在我之前的 post 上找到了解决方案关于显示/隐藏 UIView。我想添加的一件事是滑动手势。
我不想像 Nick Harris 所做的那样调整我的应用程序委托(delegate)来执行此操作。因此,如果有人对我如何做到这一点有任何想法/代码示例,我将不胜感激。
揭示一些亮点
Best Answer-推荐答案 strong>
您可以通过向左滑动手势显示来自屏幕右侧的隐藏 UIView,也可以通过相同手势再次隐藏它(这次是向右)。添加过渡。
在 .h 文件中添加 BOOL didNotSwipe 在 .m 文件 viewDidLoad 方法中添加其值 didNotSwipe = TRUE
为您的 self.view 添加具有不同选择器的左右方向的滑动手势。
UISwipeGestureRecognizer *recognizer;
recognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(swipeRight];
[recognizer setDirection:UISwipeGestureRecognizerDirectionRight];
[[self view] addGestureRecognizer:recognizer];
[recognizer release];
UISwipeGestureRecognizer *recognizer1;
recognizer1 = [[UISwipeGestureRecognizer alloc] initWithTarget:self actionselector(swipeleft];
[recognizer1 setDirection:UISwipeGestureRecognizerDirectionLeft];
[[self view] addGestureRecognizer:recognizer1];
[recognizer1 release];
当向左滑动时调用此方法:
-(void)swipeleftUISwipeGestureRecognizer *)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)swipeRightUISwipeGestureRecognizer *)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];
}
}
关于objective-c - 通过滑动 UIView 滑出导航以覆盖另一个 UIView,我们在Stack Overflow上找到一个类似的问题:
https://stackoverflow.com/questions/12066200/
|