- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Pan Gesture UIPanGestureRecognizer *panGuesture = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(panGuestureHandle:)]; [panGuesture setMinimumNumberOfTouches:1]; [panGuesture setMaximumNumberOfTouches:1]; [[self view] addGestureRecognizer:panGuesture]; } -(void) panGuestureHandle:(UIPanGestureRecognizer *) sender { NSLog(@"Pan Gesture Handling"); }
// // ViewController.h // panGesture // // 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 // panGesture // // Created by Weerachai on 11/17/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import "ViewController.h" @interface ViewController () @end @implementation ViewController - (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Pan Gesture UIPanGestureRecognizer *panGuesture = [[UIPanGestureRecognizer alloc] initWithTarget: self action: @selector(panGuestureHandle:)]; [panGuesture setMinimumNumberOfTouches:1]; [panGuesture setMaximumNumberOfTouches:1]; [[self view] addGestureRecognizer:panGuesture]; } -(void) panGuestureHandle:(UIPanGestureRecognizer *) sender { NSLog(@"Pan Gesture Handling"); UIPanGestureRecognizer *pangesture = (UIPanGestureRecognizer *)sender; CGPoint translation = [pangesture translationInView:self.view]; CGPoint imageViewPosition = imgView.center; imageViewPosition.x += translation.x; imageViewPosition.y += translation.y; imgView.center = imageViewPosition; [pangesture setTranslation:CGPointZero inView:self.view]; } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [imgView release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท