• IOS 旋转+缩放(手势识别)


    @interface NJViewController ()<UIGestureRecognizerDelegate>
    @property (weak, nonatomic) IBOutlet UIImageView *iconView;
    
    @end
    
    @implementation NJViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
        
        [self pichTest];
        [self rotationTest];
    }
    
    // 该方法返回的BOOL值决定了view是否能够同时响应多个手势
    - (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer
    {
        NSLog(@"%@ - %@", gestureRecognizer.class, otherGestureRecognizer.class);
        return YES;
    }
    
    
    - (void)pichTest
    {
        // 捏合手势
        UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] init];
        pinch.delegate = self;
        
        [self.iconView addGestureRecognizer:pinch];
        [pinch addTarget:self action:@selector(pinchView:)];
    }
    
    
    - (void)pinchView:(UIPinchGestureRecognizer *)pinch
    {
    //    NSLog(@"捏合事件 %.1f", pinch.scale);
    //    self.iconView.transform = CGAffineTransformMakeScale(pinch.scale, pinch.scale);
        // 1.0 * 0.9
        self.iconView.transform = CGAffineTransformScale(self.iconView.transform, pinch.scale, pinch.scale);
        
        pinch.scale = 1.0;
    }
    
    - (void)rotationTest
    {
        // 旋转
        UIRotationGestureRecognizer *gesture = [[UIRotationGestureRecognizer alloc] init];
        gesture.delegate = self;
        
        [self.iconView addGestureRecognizer:gesture];
        [gesture addTarget:self action:@selector(rotationView:)];
    }
    
    - (void)rotationView:(UIRotationGestureRecognizer *)gesture
    {
    //    NSLog(@"旋转事件 %.1f", gesture.rotation);
        
        
    //    每次从最初的位置开始
    //    self.iconView.transform = CGAffineTransformMakeRotation(gesture.rotation);
        
    //    在传入的transform基础上递增一个弧度
        self.iconView.transform = CGAffineTransformRotate(self.iconView.transform, gesture.rotation);
        // 将旋转的弧度清零(注意不是将图片旋转的弧度清零, 而是将当前手指旋转的弧度清零)
        gesture.rotation = 0;// 如果理解不了 , 记住就OK
    }
  • 相关阅读:
    MD5
    第一阶段冲刺(十)
    团队作业进度报告
    第一阶段冲刺(九)
    团队作业进度报告
    第一阶段冲刺(八)
    第一阶段冲刺(七)
    团队作业进度报告
    第一阶段冲刺(六)
    团队作业进度报告
  • 原文地址:https://www.cnblogs.com/liuwj/p/6599276.html
Copyright © 2020-2023  润新知