UIRotationGestureRecognizer旋转手势

概述:UIRotationGestureRecognizer旋转手势,继承于UIGestureRecognizer类,相对于UIGestureRecognizer多了两个属性值。

 /*获取旋转的弧度*/
@property (nonatomic)          CGFloat rotation; 
 /*获取旋转的速度,单位为弧度/秒*/
@property (nonatomic,readonly) CGFloat velocity;  

案例:图像的旋转

/*声明*/
@property CGFloat rotateScale;
@property CGFloat rotateRotation;
@property UIImage* rotateImage;
    /*设置初始的缩放比例*/ 
    rotateScale = 1.0;
    rotateRotation = 0;
    /*设置imageView允许用户交互,支持多点触碰*/ 
    self.image_view.userInteractionEnabled = YES;
    self.image_view.multipleTouchEnabled = YES;
    rotateImage = [UIImage imageNamed:@"rotateImage.png"];
    self.image_view.image = rotateImage;
   UIRotationGestureRecognizer *rotationRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(rotaGestureDetected:)];
    [rotationRecognizer setDelegate:self];
   /*加载到要旋转的图片*/
    [self.image_view addGestureRecognizer:rotationRecognizer];
-(void) rotaGestureDetected:(UIRotationGestureRecognizer *)recognizer {
   /*获取手势旋转的弧度*/ 
    CGFloat rotation = recognizer.rotation;
    /*根据当前缩放比计算图片缩放后的目标大小*/ 
    CGSize targetSize = CGSizeMake(rotateImage.size.width * rotateScale,
                                   rotateImage.size.height * rotateScale);
    /*对图片进行缩放、旋转*/ 
    self.image_view.image = [[rotateImage imageByScalingToSize:targetSize]
                            imageRotatedByRadians: rotateRotation + rotation];
    /*如果旋转手势结束*/ 
    if(recognizer.state == UIGestureRecognizerStateEnded)
    {
        rotateRotation = rotateRotation + rotation;
    }
}

注:了解UIGestureRecognizer类请跳转https://www.jianshu.com/p/e206dc86f89a

©著作权归作者所有,转载或内容合作请联系作者
【社区内容提示】社区部分内容疑似由AI辅助生成,浏览时请结合常识与多方信息审慎甄别。
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

相关阅读更多精彩内容

友情链接更多精彩内容