当我点击iPhone上的添加(加号)按钮时,如何制作向上动画?

时间:2011-05-01 13:20:10

标签: iphone animation

当我点击iPhone上的添加(加号)按钮时,如何制作自上而下或自下而上的动画?

2 个答案:

答案 0 :(得分:2)

如果您正在寻找“内置”API,Alex是正确的。这非常有效。

如果您想了解如何制作自己的动画,您可以在Core Animation中选择几个选项

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

但一个很好的起点只是UIView animateWithDuration

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

您还应该了解CGAffineTransform

将这些全部放在一起,这是一个从右下角将视图滑动到屏幕上的示例,让它同时淡入。 (我真的不知道我想要这样做的情况,但这是一个例子)。

我把它放在app委托中,因此很容易简单地“粘贴”到新项目中。通常情况下,你不会将任何这种性质的观点直接放到窗口中。

- (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;
}

答案 1 :(得分:1)

我认为你在想presentModalViewController;您可以使用它来显示从屏幕底部向上滑动的新屏幕。