手势 复习

//在下面写出控件的基本属性

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view.

self.view.backgroundColor = [UIColor whiteColor];

//建立一个图片视图(想要通过手势操作这个图片)

UIImageView *imaView = [[UIImageView alloc]initWithFrame:CGRectMake(20, 64, 300, 500)];

imaView.image = [UIImage imageNamed:@"S3.jpg"];

imaView.backgroundColor = [UIColor whiteColor];

[self.view addSubview:imaView];

[imaView release];

imaView.userInteractionEnabled = YES;

//轻拍手势 最常用到的手势

UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapclick:)];

[imaView addGestureRecognizer:tap];

[tap release];

//需要触碰几次

tap.numberOfTapsRequired = 3;

//需要几个手指触摸

tap.numberOfTouchesRequired = 2;

//其次重要的手势 长按

UILongPressGestureRecognizer *lp = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(lpclick:)];

[imaView addGestureRecognizer:lp];

[lp release];

lp.numberOfTouchesRequired = 2;

lp.minimumPressDuration = 2;

}

//每个手势都需要用到其中的方法

//长按的方法

- (void)lpclick: (UILongPressGestureRecognizer *)lp

{

//如果这个状态是长按的情况下 输出"长按"

if (lp.state == UIGestureRecognizerStateBegan) {

NSLog(@"长按");

}

}

//轻拍的方法

- (void)tapclick: (UITapGestureRecognizer *)tap

{

NSLog(@"轻拍");

}

//以上两个手势最为常见

最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容