标签:ios开发 手势 uigesturerecognizer uitapgesturerecogniz
//
// ViewController.m
// 手势
//
// Created by Lotheve on 15/6/13.
// Copyright (c) 2015年Lotheve. All rights reserved.
//
#import "ViewController.h"
@interface ViewController ()
{
UITapGestureRecognizer *_tap; //点击
UIPanGestureRecognizer *_pan; //拖拽
UIPinchGestureRecognizer *_pinch; //捏合
UIRotationGestureRecognizer *_rotation; //旋转
UISwipeGestureRecognizer *_swipe; //轻扫
UILongPressGestureRecognizer *_longpress; //长按
}
@property (nonatomic, weak) IBOutlet UIView *testView;
@end
@implementation ViewController
- (void)viewDidLoad {
[super viewDidLoad];
[self addTapGesture];
[self addPanGesture];
[self addPinchGesture];
[self addRotationGesture];
[self addSwipeGesture];
[self addLongpressGesture];
//手势谦让
[self gestureHumility];
}
#pragma mark - 手势
//单击
- (void)addTapGesture{
_tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
_tap.numberOfTapsRequired = 1;
[_testView addGestureRecognizer:_tap];
}
//拖拽
- (void)addPanGesture{
_pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
_pan.minimumNumberOfTouches = 1;
[_testView addGestureRecognizer:_pan];
}
//捏合
- (void)addPinchGesture{
_pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
[_testView addGestureRecognizer:_pinch];
}
//旋转
- (void)addRotationGesture{
_rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
[_testView addGestureRecognizer:_rotation];
}
//轻扫
- (void)addSwipeGesture{
_swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];
//指定扫动方向
_swipe.direction = UISwipeGestureRecognizerDirectionDown;
[_testView addGestureRecognizer:_swipe];
}
//长按
- (void)addLongpressGesture{
_longpress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longpressAction:)];
[_testView addGestureRecognizer:_longpress];
}
#pragma mark - 动作
//单击
- (void)tapAction:(UITapGestureRecognizer *)tap{
NSLog(@"单击");
}
//拖拽
- (void)panAction:(UIPanGestureRecognizer *)pan{
NSLog(@"拖拽");
CGPoint point = [pan translationInView:_testView];
pan.view.transform = CGAffineTransformMakeTranslation(point.x, point.y);
}
//捏合
- (void)pinchAction:(UIPinchGestureRecognizer *)pinch{
NSLog(@"捏合");
pinch.view.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
}
//旋转
- (void)rotationAction:(UIRotationGestureRecognizer *)rotation{
NSLog(@"旋转");
rotation.view.transform = CGAffineTransformMakeRotation(rotation.rotation);
}
//轻扫
- (void)swipeAction:(UISwipeGestureRecognizer *)swipe{
NSLog(@"向下轻扫");
}
//长按
- (void)longpressAction:(UILongPressGestureRecognizer *)longpress{
NSLog(@"长按");
}
#pragma mark - privatemethods
- (void)gestureHumility{
[_pan requireGestureRecognizerToFail:_swipe];
}
@end
IOS开发—6种常用手势UIGestureRecognizer介绍
标签:ios开发 手势 uigesturerecognizer uitapgesturerecogniz
原文地址:http://blog.csdn.net/lotheve/article/details/46482989