Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

UIView block animation move view left to right and back to left

I wan't to animate a view that's shaped as an arrow, and I want it to animate from left to right, left to right and so on..

This code below is not working, I'm guessing I need a path, but don't know how to do that in a UIView block animation.

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

} completion:^(BOOL finished) {

}];
like image 752
the Reverend Avatar asked Dec 30 '11 03:12

the Reverend


1 Answers

You can use UIViewAnimationOptionAutoreverse option, try the code below:

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];

It'll repeat move from right to left, left to right, ... smoothly.

like image 182
Kjuly Avatar answered Oct 24 '22 04:10

Kjuly