Gestures
- 手勢分為兩種,分散的、連續的,分散的給其target單一動作信號,連續的需要發送持續信號。
- The userInteractionEnabled property of the view is set to YES.
Image views and labels set this property to NO by default.
點擊:UIPanGestureRecognizer
- The number of taps was equal to the number specified in the numberOfTapsRequired property.
- The number of fingers was equal to the number specified in the numberOfTouchesRequired property.
長按:UILongPressGestureRecognizer
- The tap duration was greater than what is specified in the minimumPressDuration property.
拖動:UIPanGestureRecognizer
- The number of touches is between the values specified in the minimumNumberOfTouches and maximumNumberOfTouches properties.
- For a UIScreenEdgePanGestureRecognizer object, the edges property is configured and touches started at the appropriate edge.
滑動:UISwipeGestureRecognizer
A swipe requires the user’s finger to move in a specific direction and not deviate significantly from the main direction of travel.
The direction of the swipe matches the value in the direction property.
捏合:UIPinchGestureRecognizer
- At least two fingers are touching the screen.
- You are applying scale factors to your content correctly. Exponential growth of a value happens when you simply apply the scale factor to the current value.
旋轉:UIRotationGestureRecognizer
- You are applying rotation factors to your content correctly. Over-rotation happens when you apply the same rotation value more than once. To fix this problem, set the rotation property to 0.0 after applying the current rotation value to your content.
處理多個手勢時,遵守這個代理 UIGestureRecognizerDelegate 的 shouldRecognizeSimultaneouslyWithGestureRecognizer 方法,可以解決多個手勢沖突的問題。
Responders
A responder object -> UIResponder class -> UIApplication/UIViewController/UIView
Events continue to flow up the responder chain until they are handled.
事件傳遞:UIApplication -> UIWindow -> 根據事件類型,傳遞給Object
事件類型可以分為:
Touch events 傳遞給發生touch事件的view,也就是 hit-test View
Hit-testing 檢查touch事件發生在哪個view上,迭代的檢查是否發生在這個view上,其最小的包含touch事件發生點的view成為hit-test ViewMotion and remote control events 傳遞給first responder
大致有這么幾類:Device Orientation、Shake Gestures、Accelerometer Events、Gyroscope Events
事件響應:由下到上,自己不能響應時,傳給其父類