0

I'm new to Xcode and I can't find anything on this. I want to use UIViewAnimationCurve to move a UIImage from the lower left corner of the view to the upper left. I know the iPhone origin is upper left. How do I change this to the lower left so the animation can end in the upper right? This is what I have so far:

[UIView animateWithDuration:2.0
                      delay:2
                    options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction
                 animations:^{[MyImage setFrame:CGRectMake(0,200, 82, 78)]; }
                 completion:^(BOOL finished) {
                     [MyImage setFrame:CGRectMake(200,0, 82, 78)];
                 }];
Scott Berrevoets
  • 16,921
  • 6
  • 59
  • 80

1 Answers1

0

You want to (a) establish the view's origin in the lower left corner and then (b) animate the transition to the upper left corner.

//  step a
[MyImage setFrame:CGRectMake(0, 200, 82, 78)];

[UIView animateWithDuration:2.0
                      delay:2
                    options:UIViewAnimationCurveLinear | UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                   //  step b
                   [MyImage setFrame:CGRectMake(0, 0, 82, 78)];
                  }
                 completion:nil];

The view's frame will be set during the animation, no need for that work to be done in the completion block as well.

NB: your phrase "I want to use UIViewAnimationCurve..." is very misleading. A more commonplace way to phrase your request would have been "I want to use UIView animations...". To be very clear, the UIViewAnimationCurve enum refers to the rate at which the animation is animated, start-to-finish; UIViewAnimationCurveLinear means that the animation will proceed start-to-finish in a smooth, linear rate.

Thompson
  • 1,098
  • 11
  • 25