【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
来源:互联网 发布:mac svn客户端使用教程 编辑:程序博客网 时间:2024/06/07 21:00
在iOS 7还没有发布的时候,各种App实现各种的swipe to pop效果,比如这里有一份简单的demo。
在iOS 7上,只要是符合系统的导航结构:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions{ self.window = [[[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]] autorelease]; // Override point for customization after application launch. self.viewController = [[[ViewController alloc] initWithNibName:@"ViewController" bundle:nil] autorelease]; self.navController = [[[UINavigationController alloc] initWithRootViewController:self.viewController] autorelease]; self.window.rootViewController = self.navController; [self.window makeKeyAndVisible]; return YES;}
就能够拥有原生的漂亮效果:
遗憾的是目前项目代码里没有遵循iOS系统的导航结构,使得无法利用这点好处。所以我考虑使用新增的UIScreenEdgePanGestureRecognizer手势:
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { UIScreenEdgePanGestureRecognizer *left2rightSwipe = [[[UIScreenEdgePanGestureRecognizer alloc] initWithTarget:self action:@selector(handleSwipeGesture:)] autorelease]; [left2rightSwipe setDelegate:self]; [left2rightSwipe setEdges:UIRectEdgeLeft]; [self.view addGestureRecognizer:left2rightSwipe]; }}- (void)handleSwipeGesture:(UIScreenEdgePanGestureRecognizer *)gestureRecognizer{ [self.navigationController popViewControllerAnimated:YES];}
刚加上去的时候各种无法触发,很郁闷——毕竟是在既有代码添加,而不是在一个干净的工程上。
后来发现现有代码实现了是否开始解释touch的代理函数,稍作修改得以生效:
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{ if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(@"7.0")) { if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) { return YES; } }
生效了以后但是体验不好,感觉不灵敏。原来是已经添加过tapGesture,受了影响,又做了进一步修改:
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldBeRequiredToFailByGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer{ BOOL result = NO; if ([gestureRecognizer isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) { result = YES; } return result;}
如此一番才觉得尚可。
上面这个代理函数的描述如下:
Asks the delegate if a gesture recognizer should be required to fail by another gesture recognizer.
gestureRecognizer和otherGestureRecognizer之间到底是怎样的一个影响关系呢?
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- iOS - Swipe to pop效果
- iOS添加边缘手势( UIScreenEdgePanGestureRecognizer)实现侧滑效果
- swipe笔记 swipe.js 轻松实现手机端滑动效果
- IOS 的 7 中手势的介绍 和详细使用(UIGestureRecognizer) UIScreenEdgePanGestureRecognizer
- android 控件 swipe+recyvler实现分页效果
- iOS pushViewController 实现push 和pop 默认动画效果
- 【ios】AddChildViewController 实现 Pop View
- 实现Material风格的滑动刷新Swipe to Refresh
- 实现Material风格的滑动刷新Swipe to Refresh
- iOS学习之——UIScreenEdgePanGestureRecognizer
- 使用facebook pop 与 CAShapeLayer 实现 画线条的动画效果
- ios 滑动swipe识别
- swipe.js工具包实现手机web滑动轮播效果存在jQuery对象不能使用问题并解决(个人项目经验)
- 使用GPUImage实现iOS 7的模糊效果
- 使用GPUImage实现iOS 7的模糊效果
- 使用UIScreenEdgePanGestureRecognizer写iOS7侧边栏
- Key-Value型数据库自结
- java的内存泄露
- poj 1837 0-1背包问题
- Android开发 之 多个Activity时的完美退出方法
- 剖析Hello World
- 【iOS 7】使用UIScreenEdgePanGestureRecognizer实现swipe to pop效果
- C++ 实现 算数表达式求值
- cocos2d-x节点(TransformUtils.h)API
- cocos2d-x节点(CCVertex.h)API
- cocos2d-x节点(ccUtils.h)API
- cocos2d-x节点(ccUTF8.h)API
- IDA 字符串解密脚本
- hdu 4771 Stealing Harry Potter's Precious
- UVa 10812 Beat the Spread! (陷阱)