开发者

In UIPinchGestureRecognizer get number of fingures involed in triggering the gesture?

In UIPinchGestureRec开发者_JAVA百科ognizer how get number of fingures involed in triggering the gesture?


From UIPinchGestureRecognizer Class Reference:

UIPinchGestureRecognizer is a concrete subclass of UIGestureRecognizer that looks for pinching gestures involving two touches

Two touches.

Update

@omz said about numberOfTouches method, inherited from UIGestureRecognizer. In UIPinchGesstureRecognizer it always return 2 or 1 (when user finishing gesture and take one finger from the screen).

Update 2

This gesture always triggering by 2 fingers as said in documentation.


You can use the -numberOfTouches method (declared in UIGestureRecognizer, which is the superclass).


check out these Apple docs!

And I quote out of this:

To handle multitouch events, you must first create a subclass of a responder class. This subclass could be any one of the following:

  • A custom view (subclass of UIView)
  • A subclass of UIViewController or one of its UIKit subclasses
  • A subclass of a UIKit view or control class, such as UIImageView or UISlider
  • A subclass of UIApplication or UIWindow (although this would be rare)
  • A view controller typically receives, via the responder chain, touch events initially sent to its view if that view does not override the touch-handling methods.

For instances of your subclass to receive multitouch events, your subclass must implement one or more of the UIResponder methods for touch-event handling, described below. In addition, the view must be visible (neither transparent or hidden) and must have its userInteractionEnabled property set to YES, which is the default.

The following sections describe the touch-event handling methods, describe approaches for handling common gestures, show an example of a responder object that handles a complex sequence of multitouch events, discuss event forwarding, and suggest some techniques for event handling.

The Event-Handling Methods During a multitouch sequence, the application dispatches a series of event messages to the target responder. To receive and handle these messages, the class of a responder object must implement at least one of the following methods declared by UIResponder, and, in some cases, all of these methods:

  • (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event;
  • (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event;
  • (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event;
  • (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event

The application sends these messages when there are new or changed touches for a given touch phase:

  • It sends the touchesBegan:withEvent: message when one or more fingers touch down on the screen.
  • It sends the touchesMoved:withEvent: message when one or more fingers move.
  • It sends the touchesEnded:withEvent: message when one or more fingers lift up from the screen.
  • It sends the touchesCancelled:withEvent: message when the touch sequence is cancelled by a system event, such as an incoming phone call.

Each of these methods is associated with a touch phase; for example, touchesBegan:withEvent: is associated with UITouchPhaseBegan. You can get the phase of any UITouch object by evaluating its phase property.

Each message that invokes an event-handling method passes in two parameters. The first is a set of UITouch objects that represent new or changed touches for the given phase. The second parameter is a UIEvent object representing this particular event. From the event object you can get all touch objects for the event or a subset of those touch objects filtered for specific views or windows. Some of these touch objects represent touches that have not changed since the previous event message or that have changed but are in different phases.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜