开发者

How do I make an up to down animation when I click the add (plus) button on the iPhone?

开发者 https://www.devze.com 2023-03-02 02:59 出处:网络
How do I make a top to down or down to top animation when I click the add 开发者_如何学编程(plus) button on the iPhone?If you are looking for the \"Built In\" API,Alex is correct.And that works perfec

How do I make a top to down or down to top animation when I click the add 开发者_如何学编程(plus) button on the iPhone?


If you are looking for the "Built In" API, Alex is correct. And that works perfectly well.

If you are looking to understand how do make your own animations, you have several options in Core Animation

http://developer.apple.com/library/mac/#documentation/Cocoa/Conceptual/CoreAnimation_guide/Introduction/Introduction.html

but a great starting point is simply the UIView animateWithDuration

http://developer.apple.com/library/ios/#documentation/uikit/reference/UIView_Class/UIView/UIView.html

you should also get to know the CGAffineTransform

putting this all together, here is an example of sliding a view onto screen from the bottom right, having it fade in at the same time. (I dont really know a situation where I would want to do that, but its an example).

I put this in the app delegate so its easy to simply "paste" into a new project. Normally you would not put any views of this nature directly into the window.

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
    // Override point for customization after application launch.


    UIWindow *w = [[UIWindow alloc]initWithFrame:[[UIScreen mainScreen] bounds]];;
    self.window = w; //property defined in the .h file
    [w release];




    UIView *v = [[UIView alloc]initWithFrame:CGRectMake(0, 0, 100, 100)];
    v.backgroundColor = [UIColor redColor];
    v.center=self.window.center;
    v.alpha=0;
    [self.window addSubview:v];

    //if you ran the code to here, you would see a square in the center of the window.
    //now lets move the square off  (off screen)  with a transform and then animate it back (on screen)

    CGAffineTransform t = CGAffineTransformMakeTranslation(160+50, 240+50); //place the view just off screen, bottom right
    v.transform=t;

    //if you ran the code to here, you wouldnt see anything as the squre is placed just off screen, bottomr right

    [UIView animateWithDuration:.5  //make the animation last .5 seconds
                          delay:.3  //wait .3 seconds before performing the animation
                        options:UIViewAnimationOptionCurveEaseOut  //slow down as it reaches its destination
                     animations:^
     {
         v.transform=CGAffineTransformIdentity; //reset any transformation
         v.alpha=1.0; //fade it in

     }
                     completion:^(BOOL finished){} //nothing to do when it completes
     ];



    [self.window makeKeyAndVisible];
    return YES;
}


I think you're thinking of presentModalViewController; you can use it to present a new screen that slides up from the bottom of the screen.

0

精彩评论

暂无评论...
验证码 换一张
取 消