33

我想在我的 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];
4

5 回答 5

80

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

// 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
}];
于 2012-03-30T18:31:01.933 回答
5

如果你想要像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" ,这只会在按钮的图像视图属性上生成动画。希望它有助于一切顺利。

于 2016-02-17T11:58:30.257 回答
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
                     }];
于 2012-03-30T17:42:36.377 回答
0

斯威夫特 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
    }
于 2015-11-26T09:27:00.417 回答
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];
 }
于 2016-09-21T10:13:46.090 回答