UIKit之UIGestureRecognizer

   // 手势识别器
   // 7 个子类 : 轻拍手势 . 平移手势 . 轻扫手势 . 缩放手势 . 旋转手势 . 长按手势 . 以及 屏幕边界平移手势
   // 1. 轻拍手势
   UITapGestureRecognizer*tap  = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapAction:)];
   // 往相应的控件上添加手势
    [self.rootV.Imv addGestureRecognizer:tap];
   // 连击次数
   //tap.numberOfTapsRequired = 2;
   // 点击手指数
   //tap.numberOfTouchesRequired = 2;
   // UIImageView的用户交互默认是关闭的 需要打开
   self.rootV.Imv.userInteractionEnabled=YES;
   // 2. 长按手势
   UILongPressGestureRecognizer*longTap = [[UILongPressGestureRecognizer alloc]initWithTarget:self action:@selector(longTapAction:)];
   // 设置最短长按时间
    longTap.minimumPressDuration= 0.01;
    [self.rootV.Imv addGestureRecognizer:longTap];
   // 3. 旋转手势
   UIRotationGestureRecognizer*rotation = [[UIRotationGestureRecognizer alloc]initWithTarget:self action:@selector(rotationAction)];
  // [self.rootV.Imv addGestureRecognizer:rotation];
   // 4. 捏合手势
   UIPinchGestureRecognizer*pinch = [[UIPinchGestureRecognizer alloc]initWithTarget:self action:@selector(pinchAction:)];
    [self.rootV.Imv addGestureRecognizer:pinch];
   // 5. 平移手势
   UIPanGestureRecognizer*pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(panAction)];
   //[self.rootV.Imv addGestureRecognizer:pan];
   // 6. 轻扫手势
   UISwipeGestureRecognizer*swipe = [[UISwipeGestureRecognizer alloc]initWithTarget:self action:@selector(swipeAction)];
   //[self.rootV.Imv addGestureRecognizer:swipe];
   // 7. 屏幕边缘轻扫手势
   UIScreenEdgePanGestureRecognizer*screenEdge = [[UIScreenEdgePanGestureRecognizer alloc]initWithTarget:self action:@selector(screenEdgeAction)];
    //[self.rootV.Imv addGestureRecognizer:screenEdge];
}

- (void)tapAction:(UITapGestureRecognizer*)sender{
   NSLog(@"轻拍手势");
   UIImageView*temp = (UIImageView*)sender.view;
    temp.image= [UIImage imageNamed:@"2"];
}
- (void)longTapAction:(UILongPressGestureRecognizer*)sender{
   NSLog(@"长按手势");
   if(sender.state==UIGestureRecognizerStateBegan) {
        [UIView animateWithDuration:1animations:^{
       CGRecttemp = sender.view.frame;
        temp.size.width+= 50;
        temp.size.height+=50;
        sender.view.frame= temp;
        }];    
    }elseif(sender.state==UIGestureRecognizerStateEnded){
        [UIView animateWithDuration:1animations:^{
           CGRecttemp = sender.view.frame;
            temp.size.width-= 50;
            temp.size.height-=50;
            sender.view.frame= temp;
        }];
    }   
}
- (void)rotationAction{
   NSLog(@"旋转手势");
}
- (void)pinchAction:(UIPinchGestureRecognizer*)sender{
   NSLog(@"捏合手势");
    sender.view.transform=CGAffineTransformScale(sender.view.transform, sender.scale, sender.scale);
    sender.scale= 1;   
}
- (void)panAction{
   NSLog(@"平移手势");
}
- (void)swipeAction{
   NSLog(@"轻扫手势");
}
- (void)screenEdgeAction{
   NSLog(@"屏幕边缘轻扫手势");
}

UIImageView加载动图

// 1. 声明属性
@property(nonatomic,retain)UIImageView*Image;
// 2. 初始化
self.Image = [[UIImageView alloc]initWithFrame:CGRectMake(50, 100, 158, 212)];
    self.Image.backgroundColor = [UIColor whiteColor];
    [self addSubview:self.Image];
// 3.使用
NSMutableArray *imageArr = [NSMutableArray array];
    for (int i = 1; i < 19; i ++) {
            NSString *name = [NSString stringWithFormat:@"%d.tiff",i];
            [imageArr addObject:[UIImage imageNamed:name]];
        }
// 设置动态图图片数组
        self.Image.animationImages = imageArr;
// 设置播放一次的时间
        self.Image.animationDuration = 0;
// 设置重复次数
        self.Image.animationRepeatCount = 0;
// 开始动画
        [self.Image startAnimating];
// 结束动画
//[self.Image stopAnimating];
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容

  • 前不久做了一个生成快照的需求,其中用到 SDWebImage 来下载图片,在使用该框架的过程中也遇到了一些问题,索...
    ShannonChenCHN阅读 14,143评论 12 241
  • 、;(function(){ $(function(){ console.log('hello world'); ...
    delco阅读 260评论 0 0
  • md2
    凡眼观世界阅读 209评论 0 0
  • 杀手生来并不是个杀手,他是个孩子。孤儿。 是在一个没有曙光的清晨,天气阴沉,他被一个叫S的男人收养,那个他...
    林二狗阅读 761评论 2 10
  • 当你走进这欢乐场 背上所有的梦与想 各色的脸上各色的妆 没人记得你的模样 三巡酒过你在角落 固执的唱着苦涩的歌 听...
    楠楠521阅读 896评论 0 1