iOS手勢UIGestureRecognizer

來源:互聯網
上載者:User
文章目錄
  • 4.UISwipeGestureRecognizer (手指在螢幕上滑動操作手勢)
  • 5.UIRotationGestureRecognizer (手指在螢幕上旋轉操作)
  • 6.UILongPressGestureRecognizer (長按手勢)

UIGestureRecognizer是一個抽象類別,定義了所有手勢的基本行為,它有6個子類處理具體的手勢:

1.UITapGestureRecognizer (任意手指任意次數的點擊)

// 點擊次數

numberOfTapsRequired

// 手指個數

numberOfTouchesRequired   

UITapGestureRecognizer *tapGestureRecognizer = [[UITapGestureRecognizer alloc] init];[tapGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[tapGestureRecognizer setNumberOfTapsRequired:2];[tapGestureRecognizer setNumberOfTouchesRequired:2];[self.view addGestureRecognizer:tapGestureRecognizer];[tapGestureRecognizer release];


2.UIPinchGestureRecognizer (兩個手指捏合動作)

// 手指捏合,大於1表示兩個手指之間的距離變大,小於1表示兩個手指之間的距離變小

scale

// 手指捏合動作時的速率(加速度)

velocity

UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] init];[pinchGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[self.view addGestureRecognizer:pinchGestureRecognizer];[pinchGestureRecognizer release];

3.UIPanGestureRecognizer (搖動或者拖拽)

// 最少手指個數

minimumNumberOfTouches

// 最多手指個數

maximumNumberOfTouches

UIPanGestureRecognizer *panGestureRecognizer = [[UIPanGestureRecognizer alloc] init];[panGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[panGestureRecognizer setMinimumNumberOfTouches:1];[panGestureRecognizer setMaximumNumberOfTouches:5];[self.view addGestureRecognizer:panGestureRecognizer];[panGestureRecognizer release];

4.UISwipeGestureRecognizer (手指在螢幕上滑動操作手勢)

// 滑動手指的個數

numberOfTouchesRequired

// 手指滑動的方向 (Up,Down,Left,Right)

direction

UISwipeGestureRecognizer *swipeGestureRecognizer = [[UISwipeGestureRecognizer alloc] init];[swipeGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[swipeGestureRecognizer setNumberOfTouchesRequired:2];[swipeGestureRecognizer setDirection:UISwipeGestureRecognizerDirectionRight];[self.view addGestureRecognizer:swipeGestureRecognizer];[swipeGestureRecognizer release];

5.UIRotationGestureRecognizer (手指在螢幕上旋轉操作)

// 旋轉方向,小於0為逆時針旋轉手勢,大於0為順時針手勢

rotation

// 旋轉速率

velocity

UIRotationGestureRecognizer *rotationGestureRecognizer = [[UIRotationGestureRecognizer alloc] init];[rotationGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[self.view addGestureRecognizer:rotationGestureRecognizer];[rotationGestureRecognizer release];

6.UILongPressGestureRecognizer (長按手勢)

// Default is 0. The number of full taps required before the press for gesture to be recognized

numberOfTapsRequired

// 需要長按的手指的個數

numberOfTouchesRequired

// 需要長按的時間,最小為0.5s

minimumPressDuration

// 手指按住允許移動的距離

allowableMovement

UILongPressGestureRecognizer *longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] init];[longPressGestureRecognizer addTarget:self action:@selector(gestureRecognizerHandle:)];[longPressGestureRecognizer setMinimumPressDuration:1.0f];[longPressGestureRecognizer setAllowableMovement:50.0];[self.view addGestureRecognizer:longPressGestureRecognizer];[longPressGestureRecognizer release];

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.