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. :)

james
  • 2,595
  • 9
  • 43
  • 70

2 Answers2

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

Community
  • 1
  • 1
Dev2rights
  • 3,469
  • 3
  • 25
  • 42
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];

                }];

            }];
        }
    }
Imodeveloper
  • 394
  • 4
  • 13
  • One thing I wanted to ask. Is there anyway to cancel the animations? Like if user pressed on button? Thanks – james Apr 28 '13 at 19:59