当前位置:编程学习 > wap >>

长按(long Press)手势

//
//  ViewController.m
//  长按手势
//
//  Created by Rio.King on 13-11-2.
//  Copyright (c) 2013年 Rio.King. All rights reserved.
//

#import "ViewController.h"

@inte易做图ce ViewController ()
@property(nonatomic, strong)UILongPressGestureRecognizer *longPressGestureRecognizer;
@property (strong, nonatomic)  UIButton *dummyButton;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    /*create the gesture recognizer*/
    self.longPressGestureRecognizer = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(handleLongPressGestures:)];
    self.longPressGestureRecognizer.delegate = self;
	/*the number of fingers that must be present on the screen */
    self.longPressGestureRecognizer.numberOfTouchesRequired = 1;
    /*maximum 100 points of movement allowed before the gesture is recognized*/
    self.longPressGestureRecognizer.allowableMovement = 100.0f;
    /*the user must press two fingers(numberOfTouchesRequired)for at least one second for the gesture to be recognized*/
    self.longPressGestureRecognizer.minimumPressDuration = 1.0;
    /*add this gesture recognizer to the view*/
    [self.view addGestureRecognizer:self.longPressGestureRecognizer];
}


-(void)handleLongPressGestures:(UILongPressGestureRecognizer *)paramSender{
    if (paramSender.state == UIGestureRecognizerStateBegan){
        NSLog(@"Long PressGesture");
    }
}



- (void)didReceiveMemoryWarning
{
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

  注意:如果正在进行长按事件,此时来了一个电话或者其它相关中断长按事件的操作,手势识别器的state将被修改为UIGestureRecognizerStateCancelled。 

补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,