UIView阻止动画从左到右,从左到右移动视图

the*_*end 13 cocoa-touch uiview uiviewanimation ios

我不想为一个形状像箭头的视图制作动画,我希望它能够从左到右,从左到右依次动画等等.

下面的代码不起作用,我猜我需要一个路径,但不知道如何在UIView块动画中这样做.

   [UIView animateWithDuration:.5 delay:0 options:UIViewAnimationOptionRepeat animations:^{
    controller.view.frame = frame1;
    controller.view.frame = frame2;

} completion:^(BOOL finished) {

}];
Run Code Online (Sandbox Code Playgroud)

Kju*_*uly 33

您可以使用UIViewAnimationOptionAutoreverse选项,尝试以下代码:

UIView * testView = [[UIView alloc] initWithFrame:CGRectMake(20.0f, 100.0f, 300.0f, 200.0f)];
[testView setBackgroundColor:[UIColor blueColor]];
[self.view addSubview:testView];

[UIView animateWithDuration:0.3f
                      delay:0.0f
                    options:UIViewAnimationOptionRepeat | UIViewAnimationOptionAutoreverse
                 animations:^{
                     [testView setFrame:CGRectMake(0.0f, 100.0f, 300.0f, 200.0f)];
                 }
                 completion:nil];

[testView release];
Run Code Online (Sandbox Code Playgroud)

它会重复从右到左,从左到右,......顺利进行.