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

轻击(tap)手势

//
//  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) UITapGestureRecognizer *tapGestureRecognizer;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
	
    self.tapGestureRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(handleTaps:)];
    /*the number of fingers that must be on the screen*/
    self.tapGestureRecognizer.numberOfTouchesRequired = 2;
    /*the total number of taps to be performed before the gesture is recognized*/
    self.tapGestureRecognizer.numberOfTapsRequired = 3;
    [self.view addGestureRecognizer:self.tapGestureRecognizer];
    
}


-(void)handleTaps:(UITapGestureRecognizer *)paramSender{
    NSUInteger touchCounter = 0;
    for (touchCounter = 0; touchCounter < paramSender.numberOfTouchesRequired; touchCounter ++) {
        CGPoint touchPoint = [paramSender locationOfTouch:touchCounter inView:paramSender.view];
        NSLog(@"@Touch #%lu:%@",(unsigned long)touchCounter + 1,NSStringFromCGPoint(touchPoint));
    }
}



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

@end
解释:
 
(1)numberOfTouches这个属性值设置为2,通过设置这个值,就表示,我们在点击的时候是需要两个手指同时来完成动作的。同样numberOfTapsRequired这个值设置为3,就表示,我们需要连续的点击三次。
 
(2)代码中有一个NSStringFromCGPoint的方法,这个方法其实就是把一个物理的位置信息CGPoint转化成一个NSString类型的数据,这样我们就可以直接打印出来以便我们的查看~ ! 
补充:移动开发 , IOS ,
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,