UI _ gestures and ui gestures
Pat gesture
// Create a pat gesture and bind the event UITapGestureRecognizer * aTapGR = [[initalloc] initWithTarget: self action: @ selector (tapGRAction :)]; // set the number of Pat times. aTapGR. numberOfTapsRequired = 1; // set the number of fingers to be touched. aTapGR. numberOfTouchesRequired = 1; // The simulator press alt to touch two fingers. // Add a gesture [self. rootView addGestureRecognizer: aTapGR]; [aTapGR release]; # pragma mark-pat gesture-(void) tapGRAction :( UITapGestureRecognizer *) sender {[self. rootView. aTextField resignFirstResponder]; // You can also disable rootVIew editing. // [self. rootView endEditing: YES];}
Long-pressed gesture
UILongPressGestureRecognizer * longPressGR = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPressGRAction :)]; [self. rootView addGestureRecognizer: longPressGR]; [longPressGR release]; # pragma mark-Long-press gesture-(void) longPressGRAction :( handle *) sender {// judgment, otherwise it will change twice if (sender. state = UIGestureRecognizerStateBegan) {CGFloat red = arc4random () % 256/255 .0; CGFloat green = arc4random () % 256/255 .0; CGFloat blue = arc4random () % 256/255 .0; self. rootView. backgroundColor = [UIColor colorWithRed: red green: green blue: blue alpha: 1] ;}}
Rotation gesture
UIRotationGestureRecognizer * rotationGR = [[UIRotationGestureRecognizer alloc] initWithTarget: self action: @ selector (rotationGRAction :)]; // Add the gesture to the image [self. rootView. opeImageView addGestureRecognizer: rotationGR]; [rotationGR release]; # pragma mark-rotation gesture-(void) rotationGRAction :( UIRotationGestureRecognizer *) sender {// operation object and Rotation Angle self. rootView. opeImageView. transform = CGAffineTransformRotate (self. rootView. opeImageView. transform, sender. rotation); // The rotation angle is 0 sender. rotation = 0; // you can replace the above two rows. // self. rootView. opeImageView. transform = CGAffineTransformMakeRotation (sender. rotation );}
Kneading gesture
UIPinchGestureRecognizer * pinchGR = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @ selector (pinchGRAction :)]; [self. rootView. opeImageView addGestureRecognizer: pinchGR]; [pinchGR release]; # pragma mark-kneading gesture-(void) pinchGRAction :( UIPinchGestureRecognizer *) sender {self. rootView. opeImageView. transform = CGAffineTransformScale (self. rootView. opeImageView. transform, sender. scale, sender. scale); // after scaling, the scaling ratio is reset to 1 sender. scale = 1 ;}
Translation gesture
UIPanGestureRecognizer * panGR = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panGRAction :)]; [self. rootView. opeImageView addGestureRecognizer: panGR]; [panGR release]; # pragma mark-translation gesture-(void) panGRAction :( alert *) sender {CGPoint = [sender translationInView: sender. view]; self. rootView. opeImageView. transform = CGAffineTransformTranslate (self. rootView. opeImageView. transform, point. x, point. y); // after translation, set the gesture to 0 relative to the view where it is located. [sender setTranslation: CGPointZero inView: sender. view];}
Swipe gesture
UISwipeGestureRecognizer * swipgr = [[UISwipeGestureRecognizer alloc] initWithTarget: self action: @ selector (swipeGRAction :)]; [self. rootView addGestureRecognizer: swipgv]; [swipgvrelease]; // a single gesture can only be swept in one direction, and multiple gestures can be written in multiple directions. direction = direction;/** typedef NS_OPTIONS (NSUInteger, UISwipeGestureRecognizerDirection) {uiswipegesturerecognizerdireright = 1 <0, direction = 1 <1, direction = 1 <2, handler = 1 <3}; */# pragma mark-sweep gesture-(void) swipeGRAction :( UISwipeGestureRecognizer *) sender {NSLog (@ "sweep gesture ");}
Sweep the screen edge
Optional * screenEdgePanGR = [[UIScreenEdgePanGestureRecognizer alloc] initWithTarget: self action: @ selector (screenEdgePanGRAction :)]; [self. rootView addGestureRecognizer: screenEdgePanGR]; [screenEdgePanGR release]; # pragma mark-screen edge cleaning gesture-(void) screenEdgePanGRAction :( UIScreenEdgePanGestureRecognizer *) sender {NSLog (@ "screen edge cleaning gesture");}-(void) didReceiveMemoryWarning {[super didreceivemorywarning]; // Dispose of any resources that can be recreated .}
Copyright Disclaimer: This article is an original article by the blogger and cannot be reproduced without the permission of the blogger.