zoukankan      html  css  js  c++  java
  • UIScrollView的左右滑动和侧滑手势冲突的解决办法

    转载自:https://blog.csdn.net/kst_123/article/details/77762811

    当ViewController中添加了一个全屏的UIScrollView的时候,UIScrollView的左滑手势会和系统的左滑返回冲突,系统的左滑返回将会失效。解决办法如下:

    自定义一个CustomScrollView继承于UIScrollView,然后重写一下gestureRecognizerShouldBegin方法。

    左边侧滑:

    - (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的代码:

    DXCustomScrollView.h

    #import <UIKit/UIKit.h>
    
    @interface DXCustomScrollView : UIScrollView
    
    @end

    DXCustomScrollView.m

    #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
  • 相关阅读:
    c语言-何为编程?
    c语言-注释
    【转】使用DirectUI技术实现QQ界面
    c语言-error C2440: “static_cast”: 无法从“UINT (__thiscall CHyperLink::* )(CPoint)”转换为“LRESULT (__thiscall CWnd::* )(CPoint)”
    系统分析师【转】
    c语言-经验之谈
    开源托管站点大全
    c语言-扑克牌小魔术
    c语言-猜数字游戏
    世界语简介
  • 原文地址:https://www.cnblogs.com/wobuyayi/p/9502714.html
Copyright © 2011-2022 走看看