Add gesture for View

Source: Internet
Author: User

[Cpp]
01. # import <UIKit/UIKit. h>
02.
03. @ interface TestGestureRecognizerViewController: UIViewController {
04. UIView * aView;
05 .}
06. @ property (nonatomic, retain) IBOutlet UIView * aView;
07. @ end
08.
09. //////////////////////////////////////// //////////////////////////////////////// ///////////////
10.
11.
12. # import "TestGestureRecognizerViewController. h"
13. # import <QuartzCore/QuartzCore. h> // import framework
14.
15. @ implementation TestGestureRecognizerViewController
16. @ synthesize aView;
17.
18.-(void) handelPan :( UIPanGestureRecognizer *) gestureRecognizer {
19. // obtain the position of the translation gesture object in self. view and use this point as the center of self. aView. This achieves the drag effect.
20. CGPoint curPoint = [gestureRecognizer locationInView: self. view];
21. [self. aView setCenter: curPoint];
22 .}
23.-(void) handelTap :( UITapGestureRecognizer *) gestureRecognizer {
24. NSLog (@ "% s" ,__ FUNCTION __);
25. [nsunloop cancelPreviousPerformRequestsWithTarget: self]; // double-click the event to cancel the delay
26 .}
27. // CLICK THE METHOD
28.-(void) handelSingleTap :( UITapGestureRecognizer *) gestureRecognizer {
29. NSLog (@ "% s" ,__ FUNCTION __);
30. [self defined mselector: @ selector (singleTap :) withObject: nil afterDelay: 0.2];
31 .}
32.-(void) singleTap :( id) sender {
33. NSLog (@ "% s" ,__ FUNCTION __);
34 .}
35.
36.-(void) viewDidLoad {
37. [super viewDidLoad];
38.
39. // create a translation gesture object, which can call handelPan: Method
40. UIPanGestureRecognizer * panGes = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (handelPan :)];
41. [self. aView addGestureRecognizer: panGes];
42. [panGes release];
43.
44. // create a click gesture object, which can call handelTap: Method
45. UITapGestureRecognizer * tapGes = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handelTap :)];
46. [self. view addGestureRecognizer: tapGes];
47. [tapGes release];
48. [tapGes setNumberOfTouchesRequired: 1]; // Number of touch points
49. [tapGes setNumberOfTapsRequired: 2]; // Number of clicks
50.
51. // create a click gesture object, which can call handelSingleTap: Method
52. UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handelSingleTap :)];
53. [self. view addGestureRecognizer: singleTap];
54. [singleTap release];
55. [singleTap setNumberOfTouchesRequired: 1]; // Number of touch points
56. [singleTap setNumberOfTapsRequired: 1]; // Number of clicks
57 .}
58.
59.-(void) dealloc {
60. [super dealloc];
61 .}
62.
63. @ end
# Import <UIKit/UIKit. h>

@ Interface TestGestureRecognizerViewController: UIViewController {
UIView * aView;
}
@ Property (nonatomic, retain) IBOutlet UIView * aView;
@ End

//////////////////////////////////////// //////////////////////////////////////// ///////////////


# Import "TestGestureRecognizerViewController. h"
# Import <QuartzCore/QuartzCore. h> // import framework

@ Implementation TestGestureRecognizerViewController
@ Synthesize aView;

-(Void) handelPan :( UIPanGestureRecognizer *) gestureRecognizer {
// Obtain the position of the translation gesture object in self. view and use this point as the center of self. aView. This achieves the drag effect.
CGPoint curPoint = [gestureRecognizer locationInView: self. view];
[Self. aView setCenter: curPoint];
}
-(Void) handelTap :( UITapGestureRecognizer *) gestureRecognizer {
NSLog (@ "% s" ,__ FUNCTION __);
[Nsunloop cancelPreviousPerformRequestsWithTarget: self]; // double-click the event to cancel the delay
}
// CLICK THE METHOD
-(Void) handelSingleTap :( UITapGestureRecognizer *) gestureRecognizer {
NSLog (@ "% s" ,__ FUNCTION __);
[Self defined mselector: @ selector (singleTap :) withObject: nil afterDelay: 0.2];
}
-(Void) singleTap :( id) sender {
NSLog (@ "% s" ,__ FUNCTION __);
}

-(Void) viewDidLoad {
[Super viewDidLoad];

// Create a translation gesture object, which can call handelPan: Method
UIPanGestureRecognizer * panGes = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (handelPan :)];
[Self. aView addGestureRecognizer: panGes];
[PanGes release];

// Create a click gesture object, which can call handelTap: Method
UITapGestureRecognizer * tapGes = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handelTap :)];
[Self. view addGestureRecognizer: tapGes];
[TapGes release];
[TapGes setNumberOfTouchesRequired: 1]; // Number of touch points
[TapGes setNumberOfTapsRequired: 2]; // Number of clicks

// Create a click gesture object, which can call handelSingleTap: Method
UITapGestureRecognizer * singleTap = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (handelSingleTap :)];
[Self. view addGestureRecognizer: singleTap];
[SingleTap release];
[SingleTap setNumberOfTouchesRequired: 1]; // Number of touch points
[SingleTap setNumberOfTapsRequired: 1]; // Number of clicks
}

-(Void) dealloc {
[Super dealloc];
}

@ End

 

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.