gesture Recognizer

- (void)viewDidLoad
{
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
    UITapGestureRecognizer *doubleTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapDetected:)]; 
    
    doubleTap.numberOfTapsRequired = 2
    
    [self.view addGestureRecognizer:doubleTap]; 
    UIPinchGestureRecognizer *pinchRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinchDetected:)]; 
    
    [self.view addGestureRecognizer:pinchRecognizer]; 
    
    UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotationDetected:)]; 
    
    [self.view addGestureRecognizer:rotationRecognizer]; 
    
    UISwipeGestureRecognizer *swipeRecognizer = [[UISwipeGestureRecognizer alloc] initWithTarget:self action:@selector(swipeDetected:)]; 
    
    swipeRecognizer.direction = UISwipeGestureRecognizerDirectionRight; 
    
    [self.view addGestureRecognizer:swipeRecognizer]; UILongPressGestureRecognizer *longPressRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPressDetected:)]; 
    
    longPressRecognizer.minimumPressDuration = 3; longPressRecognizer.numberOfTouchesRequired = 1
    
    [self.view addGestureRecognizer:longPressRecognizer];
}

- (IBAction)pinchDetected:(UIGestureRecognizer *)sender 

    CGFloat scale = [(UIPinchGestureRecognizer *)sender scale]; 
    CGFloat velocity = [(UIPinchGestureRecognizer *)sender velocity]; 
    NSString *resultString = [[NSString alloc] initWithFormat: @"Pinch - scale = %f, velocity = %f", scale, velocity]; 
    self.statusLabel.text = resultString; 


- (IBAction)rotationDetected:(UIGestureRecognizer *)sender 

    CGFloat radians = [(UIRotationGestureRecognizer *)sender rotation]; 
    CGFloat velocity = [(UIRotationGestureRecognizer *)sender velocity]; 
    NSString *resultString = [[NSString alloc] initWithFormat: @"Rotation - Radians = %f, velocity = %f", radians, velocity]; 
    self.statusLabel.text = resultString; 
}
posted @ 2012-08-29 16:14  zyip  阅读(438)  评论(0编辑  收藏  举报