博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
iOS 简单手势
阅读量:7102 次
发布时间:2019-06-28

本文共 2327 字,大约阅读时间需要 7 分钟。

hot3.png

简单的一些手势 

- (void)viewDidLoad{    [super viewDidLoad];    _imageView = [[UIImageView alloc] initWithFrame:CGRectMake(110, 160, 100, 150)];    _imageSize = CGSizeMake(100, 150);    _imageView.image = [UIImage imageNamed:@"10_0.jpg"];    [self.view addSubview:_imageView];    [_imageView release];    _imageView.userInteractionEnabled = YES;        //长按    UILongPressGestureRecognizer* longPress = [[UILongPressGestureRecognizer alloc] initWithTarget:self action:@selector(longPress:)];    //最短时间    //longPress.minimumPressDuration = 5.0;    [_imageView addGestureRecognizer:longPress];    [longPress release];        //捏合    UIPinchGestureRecognizer* pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(pinch:)];    [_imageView addGestureRecognizer:pinch];    [pinch release];        //移动    UIPanGestureRecognizer* pan = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(pan:)];    [_imageView addGestureRecognizer:pan];    [pan release];        //旋转    UIRotationGestureRecognizer* rotation = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotation:)];    [_imageView addGestureRecognizer:rotation];    [rotation release];}//旋转- (void)rotation:(UIRotationGestureRecognizer*)rotation{    _imageView.transform = CGAffineTransformMakeRotation(_rotation + rotation.rotation);    //结束时,保存当前弧度    if (rotation.state == UIGestureRecognizerStateEnded) {        _rotation += rotation.rotation;    }}//移动- (void)pan:(UIPanGestureRecognizer*)pan{    CGPoint point = [pan translationInView:self.view];    //NSLog(@"%@",NSStringFromCGPoint(point));    _imageView.center = CGPointMake(_imageView.center.x + point.x, _imageView.center.y + point.y);    // 100 10    // 110 20 120    // 130    [pan setTranslation:CGPointZero inView:self.view];}//捏合- (void)pinch:(UIPinchGestureRecognizer*)pinch{    //NSLog(@"%f",pinch.scale);    /*     100*100    1.1     110*110    1.2     */    _imageView.bounds = CGRectMake(0, 0, _imageSize.width * pinch.scale, _imageSize.height * pinch.scale);    //判断状态    //当状态等于结束的时候,我们需要保存当前大小作为imageView默认大小    if (pinch.state == UIGestureRecognizerStateEnded) {        _imageSize = _imageView.bounds.size;    }}- (void)longPress:(UILongPressGestureRecognizer*)longpress{    NSLog(@"长按");}

转载于:https://my.oschina.net/liuchuanfeng/blog/205590

你可能感兴趣的文章
GoLang练习实例100之009----格式输出当前时间
查看>>
JavaScript实现在线websocket WSS测试工具 -toolfk程序员工具网
查看>>
【分享】WeX5的正确打开方式(1)
查看>>
advanced_CSS_5_2
查看>>
推荐!国外程序员整理的Java资源大全
查看>>
新书《开源安全运维平台OSSIM最佳实践》亮相2016北京图书订货会
查看>>
if语句
查看>>
gcc automake autoconf m4
查看>>
异构计算完全解析-CSDN.NET
查看>>
spring boot(七):springboot+mybatis多数据源最简解决方案
查看>>
逻辑卷、物理卷、卷组 的关系
查看>>
如何 3D 打印一个密码锁
查看>>
读取超大数据文件入库可能会用到的php.ini设置
查看>>
jquery change事件
查看>>
大众点评Cat源码阅读(六)——MessageTree编码、解码字节流
查看>>
IOS离线教程下载与Dash的使用
查看>>
HOSt ip is not allowed to connect to this MySql se
查看>>
6174问题
查看>>
sql 获取字符串长度SQL
查看>>
Android之系统自带的文字外观设置及实际显示效果图 android:textAppearance
查看>>