iOS開發之手勢gesture詳解(二)

來源:互聯網
上載者:User

標籤:blog   http   os   io   strong   for   ar   art   

與其他使用者介面控制項互動

UIControl子類會覆蓋parentView的gesture.例如當使用者點擊UIButton時,UIButton會接受觸摸事件,它的parentView不會接收到.這僅適用於手勢識別重疊的預設動作的控制,其中包括:

 

  • 一根手指單擊動作:UIButton, UISwitch, UIStepper, UISegmentedControl, and UIPageControl. 
  • 一根手指擦碰動作:UISlider
  • 一根手指拖動動作:UISwitch

  包含多點觸摸的事件

在iOS中,touch是指一根手指在螢幕上滑動、移動.而手勢是指有一根或多根手指,它的類是UITouch對象.多點觸摸事件是UIEventTypeTouches

 

 

 

當發生觸摸時,會觸發下列方法:

  • touchesBegan:withEvent :觸控螢幕幕時發生
  • touchesMoved:withEvent :手指在螢幕上移動時發生
  • touchesEnded:withEvent :觸摸結束時發生,即手指離開螢幕時
  • touchesCancelled:withEvent :觸摸被系統取消時發生,如有電話時,該觸摸會被取消

 

 

改變預設的事件行程順序

你可以通過改變UIGestureRecognizer子類的屬性來改變預設的事件傳遞

  • @property(nonatomic) BOOL delaysTouchesBegan;         // default is NO.  causes all touch events to be delivered to the target view only after this gesture has failed recognition. set to YES to prevent views from processing any touches that may be recognized as part of this gesture
  • @property(nonatomic) BOOL delaysTouchesEnded;         // default is YES. causes touchesEnded events to be delivered to the target view only after this gesture has failed recognition. this ensures that a touch that is part of the gesture can be cancelled if the gesture is recognized

如果一個gesture recognizer檢測到了一個不屬於它的touch,它將手勢直接發送給它的view,此時會調用ignoreTouch:forEvent: 方法直接傳遞給view.

建立自訂gesture recognizer步驟

  • 建立UIGestureRecognizer的子類
  • #import <UIKit/UIGestureRecognizerSubclass.h>
  • 在子類沖重載下列方法
1.- (void)reset;2.- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;3.- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;4.- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;5.- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event;

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在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.