博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
UIImageView01
阅读量:6252 次
发布时间:2019-06-22

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

//
//  ViewController.m
//  UIImageView01
//
//  Created by cqy on 16/2/13.
//  Copyright © 2016年 程清杨. All rights reserved.
//
#import "ViewController.h"
@interface ViewController (){
    UIImageView *img;
}
@end
@implementation ViewController
- (void)viewDidLoad {
    [super viewDidLoad];
    //创建UIImageView
    //通过图⽚名来初始化⼀个UIImageView类。
    img = [[UIImageView alloc]initWithImage:[UIImage imageNamed:@"cat01"]];
    img.frame = CGRectMake(120, 220, 200, 300);
    [self.view addSubview:img];
    //注意:ImageView的默认是NO,是关闭交互。要将userInteractionEnabled(响应者链是否交互)设置为YES
    img.userInteractionEnabled = YES;
    //添加手势
    //轻拍⼿势:
    //创建轻拍手势识别器
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
      [self->img addGestureRecognizer:tap];
    // ⻓按⼿势
    UILongPressGestureRecognizer *longPress =
    [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longPressAction:)];
    longPress.minimumPressDuration = 0.5;
    [self->img addGestureRecognizer:longPress];
    //旋转⼿势
    // 旋转
    UIRotationGestureRecognizer *rotation =
    [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction:)];
    [self->img addGestureRecognizer:rotation];
   // 捏合⼿势:
    UIPinchGestureRecognizer *pinch =
    [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    [self->img addGestureRecognizer:pinch];
   // 平移⼿势:
    UIPanGestureRecognizer *pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction:)];
    [self->img addGestureRecognizer:pan];
    //轻扫
   
   
    // Do any additional setup after loading the view, typically from a nib.
}
// 轻拍⼿势响应⽅法
- (void)tapAction:(UITapGestureRecognizer *)sender{
    NSLog(@"我是轻拍⼿势..");
    // 换图⽚
    // 获取⼿势图⽚
    UIImageView *temp = (UIImageView *)sender.view;
    temp.image = [UIImage imageNamed:@"cat02"];
}
// ⻓按响应⽅法
- (void)longPressAction:(UILongPressGestureRecognizer *)sender{
    NSLog(@"⻓按⼿势");
   
    if (sender.state == UIGestureRecognizerStateBegan) {
        NSLog(@"⻓按开始..");
        [UIView animateWithDuration:1 animations:^{
            // 修改view的frame
            CGRect temp1 = sender.view.frame;
            temp1.size.width +=50;
            temp1.size.height +=50;
            // 修改完成附回
            sender.view.frame = temp1;
            sender.view.alpha = 0.4;
        }];
    }else if (sender.state == UIGestureRecognizerStateEnded){
        NSLog(@"⻓按结束..");
        [UIView animateWithDuration:1 animations:^{
            // 修改view的frame
            CGRect temp1 = sender.view.frame;
            temp1.size.width -=50;
            temp1.size.height -=50;
            // 修改完成附回
            sender.view.frame = temp1;
            sender.view.alpha = 1;
        }];
    } 
}
// 旋转⼿势响应⽅法
- (void)rotationAction:(UIRotationGestureRecognizer *)sender{
    NSLog(@"我是旋转⼿势..");
    sender.view.transform =
    CGAffineTransformRotate(sender.view.transform,
                            sender.rotation);
    sender.rotation = 0;
}
// 捏合⼿势响应⽅法
- (void)pinchAction:(UIPinchGestureRecognizer *)sender{
    NSLog(@"我是捏合⼿势");
    sender.view.transform =
    CGAffineTransformScale(sender.view.transform, sender.scale,
                           sender.scale);
    sender.scale = 1;
}
// 平移⼿势响应⽅法
- (void)panAction:(UIPanGestureRecognizer *)sender{
    NSLog(@"我是平移⼿势..");
    CGPoint point = [sender translationInView:sender.view];
    sender.view.transform =
    CGAffineTransformTranslate(sender.view.transform, point.x,
                               point.y);
    // 将偏移量归零
    [sender setTranslation:CGPointZero inView:sender.view];
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
@end

转载于:https://www.cnblogs.com/iQingYang/p/5193195.html

你可能感兴趣的文章
struct dev_t
查看>>
Java 原型模式
查看>>
【转】Android4.3 蓝牙BLE初步
查看>>
题目:求s=a+aa+aaa+aaaa+aa...a的值,其中a是一个数字。
查看>>
hadoop2.0 和1.0的区别
查看>>
手机web——自适应网页设计(html/css控制) - 51CTO.COM
查看>>
ibatis resultMap 的用法
查看>>
Protocol Buffer技术详解(数据编码)
查看>>
【javascript】ajax 基础
查看>>
2015 UESTC 搜索专题N题 韩爷的梦 hash
查看>>
MySQL 二进制日志过滤
查看>>
Centos下Tomcat 安装Apache Portable Runtime
查看>>
【BZOJ】2563: 阿狸和桃子的游戏
查看>>
redis 中文字符显示
查看>>
webview与JS的交互
查看>>
吴翼大神
查看>>
在Gridview如何进行每行单元格比较
查看>>
国内外MD5在线解密网站
查看>>
插件五之滚动条jquery.slimscroll.js
查看>>
187实现录制视频功能
查看>>