문제

In Ray's tutorial on UIView animation, the following code appears to do the work of making the top and bottom of a picnic basket opening and displaying what's underneath:

- (void)viewDidAppear:(BOOL)animated
{

    CGRect basketTopFrame = self.basketTop.frame;
    basketTopFrame.origin.y = -basketTopFrame.size.height;

    CGRect basketBottomFrame = self.basketBottom.frame;
    basketBottomFrame.origin.y = self.view.bounds.size.height;

    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:0.5];
    [UIView setAnimationDelay:1.0];
    [UIView setAnimationCurve:UIViewAnimationCurveEaseOut];

    self.basketTop.frame = basketTopFrame;
    self.basketBottom.frame = basketBottomFrame;

    [UIView commitAnimations];
}

It looks from this like basketFooFrame.origin.y is the positive or negative distance by which the basket elements will move. Should this be read as defining an approach of "You set the destination coordinates and the example will run?"

I am aiming for a more verbose animation than the trick above; a UIView has a particular x, y, height, width, and rotation, and I wish to animate it, with easing, to be centered horizontally and vertically, to be as tall as the viewport maybe minus some margin, and rotated back to default orientation (and revert to its prior state if clicked).

Will I get what I want by making a more elaborate copy of the code above?

Thanks in advance,

도움이 되었습니까?

해결책

UIKit animation is "set it and forget it" mostly. However, if you are doing something where you go some place, and then take it back to where you started... that's going to require two animation blocks because you can't simply say "go from point 0,0 to point 0,0 through point 20,20" You have to say "go to point 20,20 and when you are done, go to point 0,0". Example:

#import <CoreGraphics/CoreGraphics.h>

#define degreesToRadians(x) (M_PI * x / 180.0)

// ...

[UIView animateWithDuration:.25 animations:^{
  CGAffineTransform t = CGAffineTransformIdentity;
  CGAffineTransformScale(t, 2.0, 2.0);
  CGAffineTransformRotate(t, degreesToRadians(45));

  myview.transform = t;

} completion:^(BOOL finished){
    NSLog(@"step 1 done");

    [UIView animateWithDuration:.25 animations:^{

      myview.transform = CGAffineTransformIdentity;

    } completion:^(BOOL finished) {

      NSLog(@"step 2 done");

    }];

}];
라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top