ios - 使用 Core Animation 和 block 发出旋转 UIView 对象的问题

标签 ios cocoa-touch uiview core-animation

我在使用 Core Animation 旋转 UIView 子类对象以响应 UISwipeGesture 时遇到问题。

描述上下文:我有一个圆形表盘,我在 CG 中绘制并作为 subview 添加到主视图。 作为对滑动手势的响应,我指示它根据它是向左还是向右滑动向任一方向旋转 15 度。

它只会旋转一次的问题。随后的手势被识别(从触发的其他 Action 中可以看出)但动画不会重复。我可以向左走一次然后向右走一次。但是多次尝试朝任一方向前进是行不通的。这是相关代码,让我知道您的想法...

- (IBAction)handleLeftSwipe:(UISwipeGestureRecognizer *)sender 
{
    if ([control1 pointInside:[sender locationInView:control1] withEvent:nil]) 
    {
    //updates the display value
    testDisplay.displayValue = testDisplay.displayValue + 0.1;
    [testDisplay setNeedsDisplay];

    //rotates the dial
    [UIView animateWithDuration:0.25 animations:^{
        CGAffineTransform  xform = CGAffineTransformMakeRotation(radians(+15));
        control1.transform = xform;
        [control1 setNeedsDisplay];
    }];
} 

最佳答案

CGAffineTransform xform = CGAffineTransformMakeRotation(弧度(+15));

您是否总计旋转了多远。 CGAffineTransformMakeRotation 不是相加的。仅使用最新的。所以你每次都将它设置为 15,而不是每次都多 15。

关于ios - 使用 Core Animation 和 block 发出旋转 UIView 对象的问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7249403/

相关文章:

ios - 我们可以直接从文件中知道视频的自然大小吗?

ios - 当我在录音机演示中的 AppDelegate 中写入 AVAudioSession.sharedInstance().setActive(true) 时,AudioKit 无法录音

ios - 主线程在 viewDidLoad 中的并发队列上执行 dispatch_async,或者在方法内执行事务

iOS - 开始 iOS 教程 - 变量前的下划线?

ios - iOS最早注册触摸事件

ios - 通用 iOS 应用程序在 TestFlight 中的 iPad Air 2 上不兼容

ios - Xcode - 如何修复 'NSUnknownKeyException' ,原因 : … this class is not key value coding-compliant for the key X"error?

ios - 获取 NSLayoutConstraints 关联 View

ios - 截取 UIView iOS 的屏幕截图

ios - 如何实现UIView只显示在屏幕的特定区域(SWIFT)