iOS 单手旋转

最近需要做单手的旋转,但是iOS自带的都是双手的,需要自定义,查到网上有不错的Demo

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
    if (self.isCanRotate) {
        UITouch *touch = [touches anyObject];
        
        NSUInteger toucheNum = [[event allTouches] count];//有几个手指触摸屏幕
        if ( toucheNum > 1 ) {
            return;//多个手指不执行旋转
        }
        
        //_view,你想旋转的视图
        if (![touch.view isEqual:self]) {
            return;
        }
        
        /**
         CGRectGetHeight 返回控件本身的高度
         CGRectGetMinY 返回控件顶部的坐标
         CGRectGetMaxY 返回控件底部的坐标
         CGRectGetMinX 返回控件左边的坐标
         CGRectGetMaxX 返回控件右边的坐标
         CGRectGetMidX 表示得到一个frame中心点的X坐标
         CGRectGetMidY 表示得到一个frame中心点的Y坐标
         */
        
        CGPoint center = CGPointMake(CGRectGetMidX([touch.view bounds]), CGRectGetMidY([touch.view bounds]));
        CGPoint currentPoint = [touch locationInView:touch.view];//当前手指的坐标
        CGPoint previousPoint = [touch previousLocationInView:touch.view];//上一个坐标
        
        /**
         求得每次手指移动变化的角度
         atan2f 是求反正切函数 参考:http://blog.csdn.net/chinabinlang/article/details/6802686
         */
        CGFloat angle = atan2f(currentPoint.y - center.y, currentPoint.x - center.x) - atan2f(previousPoint.y - center.y, previousPoint.x - center.x);
        
        self.transform = CGAffineTransformRotate(self.transform, angle);
    }
}

Demo  http://download.csdn.net/detail/rpf2014/9759817

转载 http://blog.csdn.net/yo_yo_yang/article/details/49948545

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值