我不会动画一个像箭头一样的视图,我想让它从左到右,从左到右动画.
下面的代码不起作用,我猜想我需要一个路径,但是不知道如何在UIView块动画中这样做.
[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,200.0f)]; } completion:nil]; [testView release];
它将重复从右到左,从左到右,顺利地移动.