zoukankan      html  css  js  c++  java
  • swift4 UIScrollView滑动手势与UIPageViewController冲突解决办法

    UIPageViewController常用多页管理中,可能会碰到滑动手势与子页面中的UIScrollView滚动视图出现冲突。

    下图是我们需要的效果

    自定义一个scrollview 看代码就ok了

    class PanScroll: UIScrollView,UIGestureRecognizerDelegate {

        override init(frame: CGRect) {

            super.init(frame: frame)

        }

        

        required init?(coder aDecoder: NSCoder) {

            fatalError("init(coder:) has not been implemented")

        }

        

        func gestureRecognizer(_ gestureRecognizer: UIGestureRecognizer, shouldRecognizeSimultaneouslyWith otherGestureRecognizer: UIGestureRecognizer) -> Bool {

            

            if let swip = otherGestureRecognizer as? UIPanGestureRecognizer{

                

                if self.contentOffset.x <= 1 && self.commitTranslation(translation: swip.translation(in: self)) == .right {

                    

                    return true

                }

                

                if self.contentOffset.x >= UIScreen.main.bounds.size.width && self.commitTranslation(translation: swip.translation(in: self)) == .left {

                    

                    return true

                }

            }

            return false

        }

        

        ///MARK: pan手势方向

        enum panDic {

            case upward,down,left,right,none

        }

        

        func commitTranslation(translation:CGPoint ) ->panDic{

            let absX = fabs(translation.x)

            let absY = fabs(translation.y)

            

            // 设置滑动有效距离

            if max(absX, absY) < 2{

                return .none

            }

            

            if absX > absY  {

                if (translation.x<0) {return .left}else{return .right}

            } else if absY > absX {

                if (translation.y<0) {return .upward}else{return .down}

            }

            return .none

        }

    }

    群号:186052819
  • 相关阅读:
    解决Oracle SQL Developer无法连接远程服务器的问题
    [备忘] Automatically reset Windows Update components
    在ASP.NET MVC的Action中直接接受客户端发送过来的HTML内容片段
    Rehosting the Workflow Designer
    解决Onedrive经常无法访问的问题
    最好的简明NodeJS学习材料
    最好的Python简明教程
    在Linux(ubuntu server)上面安装NodeJS的正确姿势
    在Windows中安装NodeJS的正确姿势
    在Windows环境中开始Docker的学习和体验
  • 原文地址:https://www.cnblogs.com/zuidap/p/7326597.html
Copyright © 2011-2022 走看看