Rotate view using CGAfffineTransformRotate(使用 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 旋转视图的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持编程学习网!
本文标题为:使用 CGAfffineTransformRotate 旋转视图
基础教程推荐
- iOS4 创建后台定时器 2022-01-01
- navigator.geolocation.getCurrentPosition 在 Android 浏览器上 2022-01-01
- libGDX 从精灵或纹理中获取像素颜色 2022-01-01
- Android:getLastKnownLocation(LocationManager.NETWORK_PROVIDER 2022-01-01
- 通过重定向链接在 Google Play 中打开应用 2022-01-01
- NSString intValue 不能用于检索电话号码 2022-01-01
- 如何从 logcat 中删除旧数据? 2022-01-01
- iPhone - 获取给定地点/时区的当前日期和时间并将其与同一地点的另一个日期/时间进行比较的正确方法 2022-01-01
- AdMob 广告未在模拟器中显示 2022-01-01
- Cocos2d iPhone 非矩形精灵触摸检测 2022-01-01
