轉載自:https://blog.csdn.net/kst_123/article/details/77762811spa
當ViewController中添加了一個全屏的UIScrollView的時候,UIScrollView的左滑手勢會和系統的左滑返回衝突,系統的左滑返回將會失效。解決辦法以下:.net
自定義一個CustomScrollView繼承於UIScrollView,而後重寫一下gestureRecognizerShouldBegin方法。code
左邊側滑:blog
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self]; CGPoint location = [gestureRecognizer locationInView:self]; if (velocity.x > 0.0f&&(int)location.x%(int)[UIScreen mainScreen].bounds.size.width<60) { return NO; } return YES; }
右邊側滑:繼承
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self]; CGPoint location = [gestureRecognizer locationInView:self]; if (velocity.x > 0.0f&&(int)location.x%(int)[UIScreen mainScreen].bounds.size.width>[UIScreen mainScreen].bounds.size.width-60) { return NO; } return YES; }
奉上一個自定義的UIScrollView的代碼:ci
DXCustomScrollView.hget
#import <UIKit/UIKit.h> @interface DXCustomScrollView : UIScrollView @end
DXCustomScrollView.mit
#import "DXCustomScrollView.h" @interface DXCustomScrollView() @end @implementation DXCustomScrollView - (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer { CGPoint velocity = [(UIPanGestureRecognizer *)gestureRecognizer velocityInView:self]; CGPoint location = [gestureRecognizer locationInView:self]; if (velocity.x > 0.0f&&(int)location.x%(int)[UIScreen mainScreen].bounds.size.width<60) { return NO; } return YES; } @end