0

I am wanting to animate a ImageView's X Position and reset it if it reaches a certain X Position. For example, Start out a 700 and move to the left.. if it reaches 100 I want to reset it to 700. And do this continually over and over.

Pretty sure a timer would be needed, but not sure how to go about this as this is my first IOS app. Searching google turned up alot of animation stuff, but all was different which led to confusion. :)

2 Answers 2

0

Use this code

call [self animate:your_image_view];

    - (void)animate:(UIImageView*)your_image
    {
       if (need_to_animate)
       {
        CGRect from = CGRectMake(10, 100, 200, 200);
        CGRect to = CGRectMake(10, 700, 200, 200);

            [UIView animateWithDuration:2 animations:^{

                your_image.frame = from;

            } completion:^(BOOL finished) {

                your_image.frame = to;


                [UIView animateWithDuration:2 animations:^{

                    your_image.frame = from;

                } completion:^(BOOL finished) {

                    [self animate:your_image];

                }];

            }];
        }
    }
1
  • One thing I wanted to ask. Is there anyway to cancel the animations? Like if user pressed on button? Thanks
    – james
    Apr 28, 2013 at 19:59
0

See here how to use UIView animations iPhone UIView Animation Best Practice Alternatively set up a timer loop and then adjust the frame/center of your view

0

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.