- (void)viewDidLoad { [super viewDidLoad]; // Do any additional setup after loading the view, typically from a nib. // Long Press UILongPressGestureRecognizer *longPressGuesture = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector(longPressGuestureHandle:)]; longPressGuesture.minimumPressDuration = 1; [[self view] addGestureRecognizer:longPressGuesture]; } - (void)longPressGuestureHandle:(UILongPressGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded ) { NSLog(@"Long Press Gesture Handling"); lblResult.text = @"Long Press Gesture Handling"; } }
// // ViewController.h // longPressGesture // // Created by Weerachai on 11/17/55 BE. // Copyright (c) 2555 Weerachai. All rights reserved. // #import <UIKit/UIKit.h> @interface ViewController : UIViewController { IBOutlet UILabel *lblResult; } @end
// // ViewController.m // longPressGesture // // 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. // Long Press UILongPressGestureRecognizer *longPressGuesture = [[UILongPressGestureRecognizer alloc] initWithTarget: self action: @selector(longPressGuestureHandle:)]; longPressGuesture.minimumPressDuration = 1; [[self view] addGestureRecognizer:longPressGuesture]; } - (void)longPressGuestureHandle:(UILongPressGestureRecognizer *)sender { if (sender.state == UIGestureRecognizerStateEnded ) { NSLog(@"Long Press Gesture Handling"); lblResult.text = @"Long Press Gesture Handling"; } } - (void)didReceiveMemoryWarning { [super didReceiveMemoryWarning]; // Dispose of any resources that can be recreated. } - (void)dealloc { [lblResult release]; [super dealloc]; } @end
ช่วยกันสนับสนุนรักษาเว็บไซต์ความรู้แห่งนี้ไว้ด้วยการสนับสนุน Source Code 2.0 ของทีมงานไทยครีเอท