ios - UIView block 动画从左到右和向左移动 View

标签 ios cocoa-touch uiview uiviewanimation

我不想为箭头形状的 View 设置动画,我希望它从左到右、从左到右等等设置动画。

下面的代码不起作用,我猜我需要一个路径,但不知道如何在 UIView block 动画中执行此操作。

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

} completion:^(BOOL finished) {

}];

最佳答案

您可以使用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];

它会从右到左,从左到右,...平稳地重复移动。

关于ios - UIView block 动画从左到右和向左移动 View ,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/8675859/

相关文章:

iphone - initWithNibName : bundle: always load English nib

objective-c - 在当前 View 中访问 subview

ios - 如何正确调整通用应用程序在整个项目中使用的 UIView 的大小?

ios - CGContextClearRect 导致背景颜色为黑色

ios - 如何修复 "nib but didn' t get a UITableView"error?

iphone - 是否有框架或库和 Web 服务来通过 NTP 以毫秒精度获取原子钟时间?

ios - "Expression are not allowed at top level"在 Swift 类的函数调用中

ios - 创建一个非跟踪应用程序内网络浏览器

iphone - UIKeyboardWillShowNotification 问题

objective-c - 不断填充一个tableview