在网上搜罗了一些方法,因为我目前项目中的界面比较复杂,所以一些方法已被pass掉,目前还有以下方法可用。
方案一:
//当前为侧滑手势的时候设置scrollview手势失效才即可
NSArray *gestureArray = self.navigationController.view.gestureRecognizers;
for (UIGestureRecognizer *gesture in gestureArray) {
if ([gesture isKindOfClass:[UIScreenEdgePanGestureRecognizer class]]) {
[self.bottomView.panGestureRecognizer requireGestureRecognizerToFail:gesture];
}
}
+1s
[_smallScrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
[_bigScrollView.panGestureRecognizer requireGestureRecognizerToFail:self.navigationController.interactivePopGestureRecognizer];
方案二:新建继承自UIScrollView的类,然后将当前控制器中的ScrollView替换,在.m中重写一下方法
#import <UIKit/UIKit.h>
@interface BottomScrollView : UIScrollView
{
BOOL isBack;
}
@end
#import "BottomScrollView.h"
@implementation BottomScrollView
-(BOOL) gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer{
if([self panBack:gestureRecognizer]) {
return NO;
}
return YES;
}
- (BOOL)panBack:(UIGestureRecognizer*)gestureRecognizer{
if(gestureRecognizer == self.panGestureRecognizer) {
UIPanGestureRecognizer *pan = (UIPanGestureRecognizer*)gestureRecognizer;
CGPoint point = [pan translationInView:self];
UIGestureRecognizerState state = gestureRecognizer.state;
if(UIGestureRecognizerStateBegan== state ||UIGestureRecognizerStatePossible== state) {
CGPoint location = [gestureRecognizer locationInView:self];
if(point.x>0&& location.x<150&&self.contentOffset.x<=0) {
isBack=YES;
return YES;
}
}
}
return NO;
}
-(BOOL)gestureRecognizer:(UIGestureRecognizer*)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(nonnull UIGestureRecognizer*)otherGestureRecognizer{
if(isBack) {
isBack=NO;
return YES;
}else{
return NO;
}
}
@end
非常感谢各位大佬的分享与交流,也希望我的发布能够帮助到跟多的人。