2.0 touch events, 2.0 touch

Source: Internet
Author: User

2.0 touch events, 2.0 touch

There are three cases where UIView does not receive touch events:

 

1. Do not receive user interaction userInteractionEnabled = NO
2. Hide hidden = YES
3. Transparent alpha = 0.0 ~ 0.01
4. if the position of the child view exceeds the valid range of the parent view, the Child view cannot interact with the user. Even if clipsToBounds = NO of the parent view is set, you can see that, however, the user cannot interact with the user. The userInteractionEnabled of UIImageView is NO by default. Therefore, UIImageView and its sub-controls cannot receive touch events by default.
Methods In the touch event:  
1 // call the 2-(void) touchesBegan :( NSSet <UITouch *> *) touches withEvent :( nullable UIEvent *) event when the finger is pressed; 3 4 // call the 5-(void) touchesMoved :( NSSet <UITouch *> *) touches withEvent :( nullableUIEvent *) event when the finger moves; 6 7 // call the 8-(void) touchesEnded :( NSSet <UITouch *> *) touches withEvent :( nullableUIEvent *) event when the finger is lifted; 9 10 // cancel (abnormal exit from the screen, unexpected interruption event) 11-(void) touchesCancelled :( nullableNSSet <UITouch *> *) touches withEvent :( nullableUIEvent *) event;
1 // 3D Touch related method. The event triggered by force changes when the current Touch object is touched. The returned value is UITouchPropertyie2-(void) touchesEstimatedPropertiesUpdated :( NSSet * _ Nonnull) touches NS_AVAILABLE_IOS );

 

Related code:

1 # import "TDView. h "2 3 @ implementation TDView 4 5 // call 6-(void) touchesBegan :( NSSet *) touches withEvent :( UIEvent *) event {7 8 UITouch * t = touches. anyObject; 9 10 NSLog (@ "% ld", t. tapCount); // number of times that the target object is clicked 11 12 NSLog (@ "% @", t. window); // click the window13 NSLog (@ "% @", self. window); 14 NSLog (@ "% @", [UIApplication sharedApplication]. keyWindow); 15 16 NSLog (@ "% s", _ func _); 17} 18 19 // call 20-(void) when the finger moves on this view) touchesMoved :( NSSet *) touches withEvent :( UIEvent *) event {21 // get the touch object 22 UITouch * t = touches. anyObject; 23 24 // obtain the location of the previous vertex 25 CGPoint lastP = [t previuslocationinview: self. superview]; 26 NSLog (@ "% @ ---- location of the previous vertex", NSStringFromCGPoint (lastP )); 27 28 // obtain the current vertex position 29 CGPoint p = [t locationInView: self. superview]; 30 NSLog (@ "% @ ---- current point location", NSStringFromCGPoint (p )); 31} 32 33 // call 34-(void) touchesEnded :( NSSet *) touches withEvent :( UIEvent *) event {35 NSLog (@ "% s ", _ func _); 36} 37 38 // cancel (abnormal exit screen) 39-(void) touchesCancelled :( NSSet *) touches withEvent :( UIEvent *) event {40 NSLog (@ "% s", _ func _); 41} 42 43 @ end

 

Supplement: About NSSet and NSArray  
  How to access How to set the value How to traverse Efficiency Application scenarios
NSSet set Unordered access, not repeated. The content stored in NSSet does not have to be sorted or added. Any element in the Set, anyObject, is used to access a single element. For in High Efficiency (1) For example, you can retrieve one Cell from the cache pool without having to obtain it in the specified order. (2) when you need to store data in a collection, then, when determining whether an object exists in the Set
NSArray Array Sequential access allows repeated objects. Objects are saved in the order of addition. Access through subscript For forin   When you need to store data in a collection and then determine whether an object exists in the collection

If you have any questions, please send an e-mail to shorfng@126.com to contact me. By: Loto)

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.