Objective c 混合UIView动画和CGAffineTransformMakeRotation

Objective c 混合UIView动画和CGAffineTransformMakeRotation,objective-c,xcode,animation,uiview,cgaffinetransform,Objective C,Xcode,Animation,Uiview,Cgaffinetransform,在阅读了一些动画教程之后,我正在测试一些东西。我创建了一个带有故事板的单视图圆弧项目。我在主视图中添加了一个UIImageView,其中心位于(200200)。我正确地设置了插座 我的想法是使图像(UIImageView*bug)向左移动,然后向右旋转180°,再向右移动,向左旋转180°,依此类推 这是我的密码 viewcontroller.h @interface ViewController : UIViewController @property (nonatomic, assign)

在阅读了一些动画教程之后,我正在测试一些东西。我创建了一个带有故事板的单视图圆弧项目。我在主视图中添加了一个UIImageView,其中心位于(200200)。我正确地设置了插座

我的想法是使图像(UIImageView*bug)向左移动,然后向右旋转180°,再向右移动,向左旋转180°,依此类推

这是我的密码

viewcontroller.h

@interface ViewController : UIViewController

@property (nonatomic, assign) IBOutlet UIImageView *bug;
@end
viewcontroller.m

#import "ViewController.h"
#import <CoreGraphics/CoreGraphics.h>

@interface ViewController ()

@end

@implementation ViewController

@synthesize bug;

#pragma mark - Animations


- (void)moveToLeft
{

    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         NSLog(@"Animation 1");
                         bug.center = CGPointMake(100, 200);
                     }
                     completion:^(BOOL finished){
                        [self turnToRight];
                     }
     ];       
}

-(void)turnToRight
{
    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         NSLog(@"Animation 2");
                         bug.transform = CGAffineTransformMakeRotation(M_PI);                     }
                     completion:^(BOOL finished){
                     [self moveToRight];
                     }
     ];
}

- (void)moveToRight
{

    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         NSLog(@"Animation 3");
                         bug.center = CGPointMake(200, 200);
                     }
                     completion:^(BOOL finished){
                         [self turnToLeft];
                     }
     ];
}

-(void)turnToLeft
{
    [UIView animateWithDuration:1.0
                          delay:0.0
                        options:UIViewAnimationCurveEaseInOut
                     animations:^{
                         NSLog(@"Animation 4");

                             bug.transform = CGAffineTransformMakeRotation(0.0);
                     }
                     completion:^(BOOL finished){
                         [self moveToLeft];
                     }
     ];
}
#导入“ViewController.h”
#进口
@界面视图控制器()
@结束
@实现视图控制器
@合成虫;
#pragma标记-动画
-(无效)移动到左侧
{
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationCurveEaseInOut
动画:^{
NSLog(@“动画1”);
bug.center=CGPointMake(100200);
}
完成:^(布尔完成){
[自动转向];
}
];       
}
-(无效)转向灯
{
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationCurveEaseInOut
动画:^{
NSLog(@“动画2”);
bug.transform=CGAffineTransformMakeRotation(M_PI);}
完成:^(布尔完成){
[自动右转];
}
];
}
-(无效)向右移动
{
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationCurveEaseInOut
动画:^{
NSLog(@“动画3”);
bug.center=CGPointMake(200200);
}
完成:^(布尔完成){
[自转左];
}
];
}
-(无效)左转
{
[UIView animateWithDuration:1.0
延迟:0.0
选项:UIViewAnimationCurveEaseInOut
动画:^{
NSLog(@“动画4”);
bug.transform=CGAffineTransformMakeRotation(0.0);
}
完成:^(布尔完成){
[自动向左移动];
}
];
}
在第二次调用CGAffineTransformMakeRotation之前,一切都正常。图像向左旋转,向右旋转,向右旋转,然后出现问题!动画中断,bug移动到第一个CGAffineTransformMakeRotation的位置,然后向左旋转,步骤重复


我尝试了不同的方法,但似乎对CGAffineTransform的每个后续调用都没有考虑UIImageView的新位置,并且总是在调用它的第一个位置执行转换。我检查了很多示例,代码似乎是正确的,我只是不明白为什么将CGAffineTransformMakeRotation与常规动画混合使用会导致这种行为。

您应该使用
UIViewAnimation
选项
CurveEaseInOut
而不是
UIViewAnimationCurveEaseInOut
。它们来自不同的枚举,在使用块动画时,始终使用名称中带有
选项的块。
您指定的值为
UIViewAnimationOptionLayoutSubviews
,这可能会导致重新定位

这是我在你的代码中发现的唯一问题。如果这不是解决方案,那么您发现了一个bug:)