美文网首页
UI总结-手势

UI总结-手势

作者: Dear丶Musk | 来源:发表于2016-05-12 11:19 被阅读80次

                         UI总结-手势

常用的6种手势:

#import "ViewController.h"

@interface ViewController ()

@property(nonatomic, retain)UIImageView *imagev;

@end

@implementation ViewController

- (void)viewDidLoad {

[super viewDidLoad];

// Do any additional setup after loading the view, typically from a nib.

self.view.backgroundColor = [UIColor whiteColor];

self.imagev = [[UIImageView alloc]init];

self.imagev.frame = CGRectMake(50, 200, 350, 300);

[self.view addSubview:self.imagev];

[_imagev release];

self.imagev.image = [UIImage imageNamed:@"818006c62c85ebc153a7b5a47c5efbd3.jpg"];

//在给图片加手势等操作时,需要先打开对象的用户交互

self.imagev.userInteractionEnabled = YES;

//1.轻点手势

//创建手势

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

//给试图添加手势

[self.imagev addGestureRecognizer:tap];

[tap release];

//两个属性

//点击几下触发方法

tap.numberOfTapsRequired = 2;

//用几个手指点触发方法

tap.numberOfTouchesRequired = 1;

//2.长按手势

UILongPressGestureRecognizer *longPress = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];

[self.imagev addGestureRecognizer:longPress];

[longPress release];

//属性,长按多长时间触发方法

longPress.minimumPressDuration = 4;

//3.旋转手势

UIRotationGestureRecognizer *rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotation:)];

[self.imagev addGestureRecognizer:rotation];

[rotation release];

//4.捏合手势

UIPinchGestureRecognizer *pin = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinAction:)];

[self.imagev addGestureRecognizer:pin];

[pin release];

//5.拖拽手势

UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];

[self.imagev addGestureRecognizer:pan];

[pan release];

//6.轻扫手势

UISwipeGestureRecognizer *swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction:)];

[self.imagev addGestureRecognizer:swipe];

[swipe release];

}

#pragma mark 轻点手势的点击语法

-(void)tapAction:(UITapGestureRecognizer *)tap{

NSLog(@"图片完成点击");

}

-(void)longPressAction:(UILongPressGestureRecognizer *)longPress{

//通过手势的状态,避免重复的触发手势方法

if (longPress.state == UIGestureRecognizerStateBegan) {

NSLog(@"长按触发");

}

}

#pragma mark 旋转手势的点击语法

-(void)rotation:(UIRotationGestureRecognizer *)ro{

self.imagev.transform = CGAffineTransformMakeRotation(ro.rotation);

}

#pragma mark 捏合手势的点击语法

-(void)pinAction:(UIPinchGestureRecognizer *)pinch{

self.imagev.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);

}

#pragma mark 拖拽手势的点击语法

-(void)panAction:(UIPanGestureRecognizer *)pan{

//当前手势进过的坐标

CGPoint point = [pan translationInView:self.imagev];

//self.imagev.transform = CGAffineTransformMakeTranslation(point.x, point.y);

self.imagev.center = CGPointMake(self.imagev.center.x + point.x , self.imagev.center.y + point.y);

[pan setTranslation:CGPointZero inView:self.imagev];

}

#pragma mark 轻扫手势的点击语法

-(void)swipeAction:(UISwipeGestureRecognizer *)swipe{

NSLog(@"轻扫触发");

}

运行结果如下图所示:

相关文章

  • UI总结-手势

    UI总结-手势 常用的6种手势: #import "ViewController.h" @...

  • UI手势

    手势识别器有:轻拍 长按 旋转 捏合 拖拽 清扫 屏幕边缘拖拽 在使用这些手势识别器时 先打开用户交互 image...

  • UI手势

    UIGestureRecongnizer:NSObject 1.-(void)addGestureRecogniz...

  • UI - 手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

  • UI手势

    手势:有规律的触摸 UIGestureRecognizer抽象类 七种手势:轻拍(tap)长按(longPress...

  • UI手势

    UIGestureRecognizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象类...

  • 5.2 GestureRecognizer---UI手势

    GestureRecognizer---UI手势 基础控制器 导航栏视图控制器, 根试图控制器 单击手势 双击手势...

  • UI梳理——手势

    手势分类: 手势的创建: 方法的实现: 轻扫手势:UISwipeGestureRecognizer 长按手势: 以...

  • UI手势回顾

    UIGestureRecongnizer手势识别器 手势:有规律的触摸 UIGestureRecognizer抽象...

  • UI手势控件

    一、拖拽 示例代码: 复制代码 1 // 2 // YYViewController.m 3 // 06-拖拽事件...

网友评论

      本文标题:UI总结-手势

      本文链接:https://www.haomeiwen.com/subject/thxprttx.html