使用 CGAfffineTransformRotate 旋转视图 [英] Rotate view using CGAfffineTransformRotate

查看:25
本文介绍了使用 CGAfffineTransformRotate 旋转视图的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个要旋转的圆形图像,这样黄色和黑色的条纹圆圈就会停留在用户的手指下方并在两个方向上旋转.到目前为止我有这个:

I have a circular image which I am trying to rotate, so that the yellow and black striped circle stays under the user's finger and rotates in both directions. I have this so far:

- (void)handleJogShuttle:(UIPanGestureRecognizer *)recognizer {

    UIView *shuttle = [recognizer view];

    if ([recognizer state] == UIGestureRecognizerStateBegan ||
        [recognizer state] == UIGestureRecognizerStateChanged) {

        [recognizer view].transform = CGAffineTransformRotate([[recognizer view] transform],M_PI / 20.0f);
        [recognizer setTranslation:CGPointZero inView:[shuttle superview]];
    }
}

此外,目前,最轻微的移动都会导致视图旋转一整圈,这显然是不希望的.

Also, currently, the slightest movement can cause the view to rotate in a full circle, which is obviously not desired.

推荐答案

我怀疑这个方法被调用了很多.尝试使用 NSLog 并检查它做了多少次.无论如何,您没有正确计算角度,您可以尝试使用

I suspect this method gets called A LOT. Try using NSLog and check how many time it does. Anyway, you are not calculating the angle properly, you could try using

-(CGPoint)translationInView:(UIView *)view

从识别器中计算出正确的旋转角度.

from the recognizer to calculate the correct angle to rotate.

这篇关于使用 CGAfffineTransformRotate 旋转视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆