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 旋转视图


- GPS状态的广播接收器? 2022-01-01
- 使用自动布局向 UIScrollView 添加动态大小的视图 2022-01-01
- URL编码Swift iOS 2022-01-01
- 类似于 Mail.app 的 iPad 模态视图控制器? 2022-01-01
- 网上有没有好的 UIScrollView 教程? 2022-01-01
- 如何在 iPhone 模拟器中重置 NSUserDefaults 数据? 2022-01-01
- Xcode 7.3 中带有 UILabel 的 UIStackView 2022-01-01
- UITextView 内容插图 2022-01-01
- SetOnItemSelectedListener上的微调程序错误 2022-01-01
- 在 Iphone SDK 的导航栏上添加多个按钮 2022-01-01