iOS - 动画效果 - 图像弹出

时间:2012-03-30 17:35:58

标签: iphone ios animation uianimation

我想在我的iphone应用程序中“弹出”一个图像,而不是只是出现。通过“pop-in”我的意思是它会从一个小点增长到它的实际大小。作为参考,这与Keynote中的“pop”动画效果完全相同。 我对iOS动画完全不熟悉,所以如果有人能指出我需要使用的动画效果方向,我将非常感激。

由于

布赖恩

更新 我已从下面的建议中添加了此代码。这可以工作,但它可以缩小我的图像,而不是向上。我知道这是因为我有0.01作为变换比例尺寸,但我想知道如何开始使用大小为0.0的图像并将其缩放到1.只需将图像的大小设置为0? 感谢

[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration: 0.2];
image.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView setAnimationDelegate:self];
[UIView commitAnimations];

5 个答案:

答案 0 :(得分:79)

您正在寻找的效果是这样的:

// instantaneously make the image view small (scaled to 1% of its actual size)
view.transform = CGAffineTransformMakeScale(0.01, 0.01);
[UIView animateWithDuration:0.2 delay:0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    // animate it to the identity transform (100% scale)
    view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished){
    // if you want to do something once the animation finishes, put it here
}];

答案 1 :(得分:4)

如果您想要像 Facebook 那样喜欢任何帖子,请使用此

-(void)animateButton:(UIButton *)sender{
UIButton * btn = (UIButton *)sender;
[UIView animateWithDuration:0.3/1.5 animations:^{
    btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.4, 1.4); // scales up the view of button 
} completion:^(BOOL finished) {
    [UIView animateWithDuration:0.3/2 animations:^{
        btn.transform = CGAffineTransformScale(CGAffineTransformIdentity, 0.7, 0.7);// scales down the view of button
    } completion:^(BOOL finished) {
        [UIView animateWithDuration:0.3/2 animations:^{
            btn.transform = CGAffineTransformIdentity; // at the end sets the original identity of the button
        }];
    }];
}];}

当您想要为视图设置动画时,只需调用此方法

如果按钮上有文字和图像,并且您只想为按钮的图像设置动画,则只需将“btn”替换为“btn.imageView”,这样就可以在按钮的图像视图属性上生成动画。 希望能帮助到你 一切顺利。

答案 2 :(得分:0)

您必须为视图的框架设置动画,将其从零缩小到最终状态。 这可以通过UIView块动画来完成。

因此,例如,将您的视图作为具有最终大小和位置的IBOutlet属性self.myView开始,但设置隐藏标志。 然后,当您希望它出现时,请使用以下内容:

// Save old frame as final stater and set it to zero size for the start of the animation
// But keep the same center position, so it just grows and don't move around 
CGRect oldFrame = self.myView.frame;
CGRect oldCenter = self.myView.center;

self.myView.frame = CGRectZero;
self.myView.center = oldCenter;

self.myView.hidden = NO;

NSTimeInterval duration = 0.3;

[UIView animateWithDuration:duration delay:0.0 options:UIViewAnimationOptionAllowUserInteraction animations:^{
                // New position and size after the animation should be the same as in Interface Builder
                self.myView.frame = oldFrame
    }
                     completion:^(BOOL finished){
                                                 // You can do some stuff here after the animation finished
                     }];

答案 3 :(得分:0)

Swift 2.0版

    view.transform = CGAffineTransformMakeScale(0.01, 0.01);

    UIView.animateWithDuration(0.2, delay: 0, options: .CurveEaseOut, animations: { () -> Void in
        // animate it to the identity transform (100% scale)
        self.view.transform = CGAffineTransformIdentity;

        }) { (finished) -> Void in
        // if you want to do something once the animation finishes, put it here
    }

答案 4 :(得分:0)

为此你必须使用一个简单的UIView

将UIview添加到当前视图。

- (void) initPopUpView
 {
   popup.alpha = 0;
   popup.frame = CGRectMake (160, 240, 0, 0);
   [self.view addSubview:popup];
 }

- (void) animatePopUpShow 
 {
   [UIView beginAnimations:nil context:NULL];
   [UIView setAnimationDuration:0.3];
   [UIView setAnimationDelegate:self];
   [UIView setAnimationWillStartSelector:@selector(initPopUpView)];

   popup.alpha = 1;
   popup.frame = CGRectMake (20, 40, 300, 400);

   [UIView commitAnimations];
 }