在UIScreenEdgePanGestureRecognizer中,'edges = UIRectEdge.all'的用例是什么?

时间:2017-05-23 21:45:25

标签: ios swift3 uigesturerecognizer

来自Apple API(见下文):

  1. UIScreenEdgePanGestureRecognizer具有类型的属性边 UIRectEdge

  2. UIRectEdge具有以下属性:[top,left,right,bottom,all]

  3. 我认为UIRectEdge.all的目的是包括所有其他四个方向。 但是根据我的测试(见下文),.all根本没有检测到任何方向。

    //  UIScreenEdgePanGestureRecognizer.h
    //  Copyright (c) 2012-2015 Apple Inc. All rights reserved.
    //
    
    /*! This subclass of UIPanGestureRecognizer only recognizes if the user slides their finger
    in from the bezel on the specified edge. */
        @available(iOS 7.0, *)
        open class UIScreenEdgePanGestureRecognizer : UIPanGestureRecognizer {
    
        open var edges: UIRectEdge //< The edges on which this gesture recognizes, relative to the current interface orientation
    }
    

    官方UIRectEdge结构:

    public struct UIRectEdge : OptionSet {
        public init(rawValue: UInt)
    
        public static var top: UIRectEdge { get }
        public static var left: UIRectEdge { get }
        public static var bottom: UIRectEdge { get }
        public static var right: UIRectEdge { get }
        public static var all: UIRectEdge { get }
    }
    

    但是当我们设置边缘时,边缘检测无法检测到“任何”边缘方向= UIRectEdge.all

    即。什么都不会被发现 (而不是4个方向检测,没有检测到方向) 使用此代码时:

    let myEdgePan = UIScreenEdgePanGestureRecognizer()
    myEdgePan.edges = UIRectEdge.all
    myEdgePan.maximumNumberOfTouches = 2
    myEdgePan.minimumNumberOfTouches = 1
    myEdgePan.addTarget(self, action: #selector(ViewController.myEdgePanned(_:)))
    self.view.addGestureRecognizer(coolEdgePan)
    

    相反,我需要以下解决方法来检测所有4个边缘平移方向:

    let edges : [UIRectEdge] = [.left, .right, .top, .bottom]
    
    for edge in edges {
        let myEdgePan = UIScreenEdgePanGestureRecognizer()
        myEdgePan.edges = edge
        myEdgePan.maximumNumberOfTouches = 2
        myEdgePan.minimumNumberOfTouches = 1
        myEdgePan.addTarget(self, action: #selector(ViewController.myEdgePanned(_:)))
        self.view.addGestureRecognizer(coolEdgePan)
        }
    

    有人知道'UIRectEdge.all'的用例是什么?

0 个答案:

没有答案