1. 程式人生 > >iOS手勢篇(八)-UISwipeGestureRecognizer詳解

iOS手勢篇(八)-UISwipeGestureRecognizer詳解

UISwipeGestureRecognizer作為iOS中的側滑手勢其實是用的比較多的一個手勢.側滑手勢相較於Pan拖動手勢來說.一些特殊的方法啊,屬性啊,統統木有.開啟標頭檔案也只有簡潔的兩個屬性

@property(nonatomic) NSUInteger                        numberOfTouchesRequired __TVOS_PROHIBITED; // default is 1. the number of fingers that must swipe
@property(nonatomic) UISwipeGestureRecognizerDirection direction;               // default is UISwipeGestureRecognizerDirectionRight. the desired direction of the swipe. multiple directions may be specified if they will result in the same behavior (for example, UITableView swipe delete)

以及一個方向的列舉

typedef NS_OPTIONS(NSUInteger, UISwipeGestureRecognizerDirection) {
    UISwipeGestureRecognizerDirectionRight = 1 << 0,
    UISwipeGestureRecognizerDirectionLeft  = 1 << 1,
    UISwipeGestureRecognizerDirectionUp    = 1 << 2,
    UISwipeGestureRecognizerDirectionDown  = 1 << 3
};
屬性 預設值 說明
numberOfTouchesRequired 1 預設一個手指頭滑動就行,設定為幾就需要有一個手指頭滑動才能觸發滑動手勢
direction UISwipeGestureRecognizerDirectionRight 向右滑
列舉值 說明
UISwipeGestureRecognizerDirectionRight 向右滑
UISwipeGestureRecognizerDirectionLeft 向左滑
UISwipeGestureRecognizerDirectionUp 向上滑
UISwipeGestureRecognizerDirectionDown 向下滑

注:側滑手勢容易與pan手勢衝突,建議pan手勢物件使用

requireGestureRecognizerToFail:

來避免手勢衝突