[Code Note] iOS-click Add gesture, note ios-click gesture
I ,.
2. Engineering Drawing.
3. Code.
RootViewController. h
#import <UIKit/UIKit.h>@interface RootViewController : UIViewController<UIGestureRecognizerDelegate>@end
RootViewController. m
# Import "RootViewController. h "@ interface RootViewController () @ end @ implementation RootViewController-(id) initWithNibName :( NSString *) bundle :( NSBundle *) handle {self = [super initWithNibName: nibNameOrNil bundle: nibBundleOrNil]; if (self) {// Custom initialization} return self;}-(void) viewDidLoad {[super viewDidLoad]; // Do any additional setup after loading the view. // Add the background [self addView];} # pragma-mark-functions // Add the background-(void) addView {self. title = @ "click Add gesture"; UIView * parentView = [[UIView alloc] initWithFrame: CGRectMake (50,100,200,200)]; parentView. backgroundColor = [UIColor redColor]; [self. view addSubview: parentView]; // click the gesture UITapGestureRecognizer * tapRecognize = [[using alloc] initWithTarget: self action: @ selector (handleTap :)]; tapRecognize. numberOfTapsRequired = 1; tapRecognize. delegate = self; [tapRecognize setEnabled: YES]; [tapRecognize delaysTouchesBegan]; [tapRecognize cancelsTouchesInView]; [self. view addGestureRecognizer: tapRecognize];} # pragma UIGestureRecognizer Handles-(void) handleTap :( UITapGestureRecognizer *) recognizer {NSLog (@ "--- click gesture -------");} (void) didReceiveMemoryWarning {[super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated .}