UIGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandleAction:)]; [[self view] addGestureRecognizer:gestureRecognizer]; -(void) gestureHandleAction:(UIGestureRecognizer *) sender { }
// // ViewController.h // gestureRecognizer // // Created by Weerachai on 11/17/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UIImageView *imgView; } @end
// // ViewController.m // gestureRecognizer // // Created by Weerachai on 11/17/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () { BOOL tapIsActive; } @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. tapIsActive = TRUE; UIGestureRecognizer *gestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(gestureHandleAction:)]; [[self view] addGestureRecognizer:gestureRecognizer]; } -(void) gestureHandleAction:(UIGestureRecognizer *) sender { NSLog(@"Gesture Handling"); if(tapIsActive == TRUE) { imgView.image = [UIImage imageNamed:@"girl1.jpg"]; tapIsActive = FALSE; } else { imgView.image = [UIImage imageNamed:@"girl2.jpg"]; tapIsActive = TRUE; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [imgView release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท