[IOS UI advanced, iosui advanced

Source: Internet
Author: User

[IOS UI advanced, iosui advanced
A. Gesture Recognition provided by the system1-(void) testTap {2 // create gesture reader 3 UITapGestureRecognizer * tapRec = [[using alloc] initWithTarget: self action: @ selector (tapRun :)]; 4 tapRec. numberOfTapsRequired = 3; // number of times you need to click 5 tapRec. numberOfTouchesRequired = 2; // number of points to be clicked at the same time: 6 7 // configure the gesture reader to control 8 [self. hvwView addGestureRecognizer: tapRec]; 9} 10 11/** method of event handling for the tap gesture */12-(void) tapRun :( UITapGestureRecognizer *) tapRec {13 NSLog (@ "tapRun"); 14}

 

2. long-press gesture seek: Long-press effective time numberOfTouchesRequired: required simultaneous clicks numberOfTapsRequired: Required clicks allowableMovement: Long-press valid range (starting from the click, long-Press the permitted range) ps: the target method will be continuously called when moving
1-(void) testLongPress {2 UILongPressGestureRecognizer * longRec = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @ selector (longPressRun :)]; 3 4 longRec. minimumPressDuration = 2; // long press time 5 longRec. allowableMovement = 50; // long-pressed allowed range, unit: px6 7 [self. hvwView addGestureRecognizer: longRec]; 8}
3. UISwipeGestureRecognizerdirection
1 typedef enum {2    UISwipeGestureRecognizerDirectionRight = 1 << 0,3    UISwipeGestureRecognizerDirectionLeft  = 1 << 1,4    UISwipeGestureRecognizerDirectionUp    = 1 << 2,5    UISwipeGestureRecognizerDirectionDown  = 1 << 36 } UISwipeGestureRecognizerDirection;
 
1-(void) testSwipe {2 UISwipeGestureRecognizer * swipeRec = [[delealloc] initWithTarget: self action: @ selector (swipeRun :)]; 3 swipeRec. direction = UISwipeGestureRecognizerDirectionRight; // sweep direction 4 5 [self. hvwView addGestureRecognizer: swipeRec]; 6}

 

4. kneading gesture UIPinchGestureRecognizerscale: the kneading distance.
1-(void) testPinch {2 UIPinchGestureRecognizer * rec = [[UIPinchGestureRecognizer alloc] initWithTarget: self action: @ selector (pinchRun :)]; 3 4 [self. hvwView addGestureRecognizer: rec]; 5} 6 7-(void) pinchRun :( UIPinchGestureRecognizer *) rec {8 rec. view. transform = CGAffineTransformScale (rec. view. transform, rec. scale, rec. scale); 9 10 // be sure to reset !!! Otherwise, press and hold the pinch button to add the multiples of 11 rec. scale = 1; 12}
1-(void) testRotation {2 UIRotationGestureRecognizer * rotationRec = [[UIRotationGestureRecognizer alloc] initWithTarget: self action: @ selector (rotationRun :)]; 3 4 [self. hvwView addGestureRecognizer: rotationRec]; 5} 6 7-(void) rotationRun :( UIRotationGestureRecognizer *) rec {8 rec. view. transform = CGAffineTransformRotate (rec. view. transform, rec. rotation); 9 10 // be sure to reset !!! Otherwise, the rotation11 rec. rotation = 0; 12}1-(void) testPan {2 UIPanGestureRecognizer * rec = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panRun :)]; 3 4 [self. hvwView addGestureRecognizer: rec]; 5} 6 7-(void) panRun :( UIPanGestureRecognizer *) rec {8 // get the drag distance from 9 CGPoint movedDistance = [rec translationInView: rec. view]; 10 CGPoint viewCenter = rec. view. center; 11 viewCenter. x + = movedDistance. x; 12 viewCenter. y + = movedDistance. y; 13 rec. view. center = viewCenter; 14 15 // reset drag distance 16 [rec setTranslation: CGPointZero inView: rec. view]; 17}1 @ interface ViewController () <UIGestureRecognizerDelegate>2. Set a proxy for the gesture reader that needs to be recognized at the same time
1 rec.delegate = self;
3. How to Implement the simultaneous use of the gesture Reader
1-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer combined :( UIGestureRecognizer *) combined {2 3 // All two gesture identifiers can use 4 return YES; 5}
 
1 // 2 // ViewController. m 3 // GestureRecognizerTest 4 // 5 // Created by hellovoidworld on 15/1/13. 6 // Copyright (c) 2015 hellovoidworld. all rights reserved. 7 // 8 9 # import "ViewController. h "10 11 @ interface ViewController () <UIGestureRecognizerDelegate> 12 13 @ property (weak, nonatomic) IBOutlet UIView * hvwView; 14 15 @ end 16 17 @ implementation ViewController 18 19-(void) viewDidLoad {20 [super viewDidLoad]; 21 // Do any additional setup after loading the view, typically from a nib. 22 23 // [self testTap]; 24 // [self testLongPress]; 25 // [self testSwipe]; 26 [self testRotation]; 27 [self testPinch]; 28 [self testPan]; 29} 30 31-(void) testTap {32 // create gesture reader 33 UITapGestureRecognizer * tapRec = [[UITapGestureRecognizer alloc] initWithTarget: self action: @ selector (tapRun :)]; 34. tapRec. numberOfTapsRequired = 3; // number of times to be clicked 35 tapRec. numberOfTouchesRequired = 2; // number of points to be clicked 36 at the same time // configure the gesture reader to control 38 [self. hvwView addGestureRecognizer: tapRec]; 39} 40 41/** method of event handling for the tap gesture */42-(void) tapRun :( UITapGestureRecognizer *) tapRec {43 NSLog (@ "tapRun"); 44} 45 46-(void) testLongPress {47 UILongPressGestureRecognizer * longRec = [[UILongPressGestureRecognizer alloc] ini TWithTarget: self action: @ selector (longPressRun :)]; 48 49 longRec. minimumPressDuration = 2; // long press effective time 50 longRec. allowableMovement = 50; // The allowable moving range of a long press. Unit: px 51 52 [self. hvwView addGestureRecognizer: longRec]; 53} 54 55-(void) longPressRun :( UILongPressGestureRecognizer *) rec {56 NSLog (@ "longPress"); 57} 58 59-(void) testSwipe {60 UISwipeGestureRecognizer * swipeRec = [UISwipeGestureRecognizer Alloc] initWithTarget: self action: @ selector (swipeRun :)]; 61 swipeRec. direction = uiswipegesturerecognizerdireright; // the direction of the Light sweep 62 63 [self. hvwView addGestureRecognizer: swipeRec]; 64} 65 66-(void) swipeRun :( UISwipeGestureRecognizer *) rec {67 NSLog (@ "swipe"); 68} 69 70-(void) testRotation {71 UIRotationGestureRecognizer * rotationRec = [[UIRotationGestureRecognizer alloc] initWithTarget: s Elf action: @ selector (rotationRun :)]; 72 rotationRec. delegate = self; 73 74 [self. hvwView addGestureRecognizer: rotationRec]; 75} 76 77-(void) rotationRun :( UIRotationGestureRecognizer *) rec {78 rec. view. transform = CGAffineTransformRotate (self. hvwView. transform, rec. rotation); 79 80 // be sure to reset !!! Otherwise, the rotation 81 rec will be added continuously when you press and hold the rotation. rotation = 0; 82} 83 84-(void) testPinch {85 UIPinchGestureRecognizer * rec = [[using alloc] initWithTarget: self action: @ selector (pinchRun :)]; 86 rec. delegate = self; 87 88 [self. hvwView addGestureRecognizer: rec]; 89} 90 91-(void) pinchRun :( UIPinchGestureRecognizer *) rec {92 rec. view. transform = CGAffineTransformScale (rec. view. transform, re C. scale, rec. scale); 93 94 // be sure to reset !!! Otherwise, press and hold the kneading button to overlay 95 rec. scale = 1; 96} 97 98-(void) testPan {99 UIPanGestureRecognizer * rec = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @ selector (panRun :)]; 100 rec. delegate = self; 101 102 [self. hvwView addGestureRecognizer: rec]; 103} 104 105-(void) panRun :( UIPanGestureRecognizer *) rec {106 // get the drag distance from 107 CGPoint movedDistance = [rec translationInView: rec. view]; 108 CGPoint viewCenter = rec. view. center; 109 viewCenter. x + = movedDistance. x; 110 viewCenter. y + = movedDistance. y; 111 rec. view. center = viewCenter; 112 113 // reset the drag distance from 114 [rec setTranslation: CGPointZero inView: rec. view]; 115} 116 117-(void) didReceiveMemoryWarning {118 [super didReceiveMemoryWarning]; 119 // Dispose of any resources that can be recreated.120} 121 122-(BOOL) gestureRecognizer :( UIGestureRecognizer *) gestureRecognizer failed :( UIGestureRecognizer *) failed {123 124 // both gesture identifiers can use 125 return YES; 126} 127 128 @ end at the same time
  # Mark:Because the transform deformation is used for scaling and rotation, it cannot be normally used for dragging.

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.