Iphone iOS-动画效果-图像弹出

Iphone iOS-动画效果-图像弹出,iphone,ios,animation,uianimation,Iphone,Ios,Animation,Uianimation,我希望在我的iphone应用程序“pop-in”中有一个图像出现在屏幕上,而不是仅仅出现在屏幕上。我所说的“弹出”是指它会从一个小点增长到实际大小。作为参考,这与Keynote中的“pop”动画效果完全相同。 我对iOS动画一无所知,因此如果有人能为我指出我需要使用的动画效果的方向,我将不胜感激 谢谢 布莱恩 更新 我根据下面的建议添加了这段代码。这是可行的,但它缩小了我的图像,而不是放大。我知道这是因为变换比例大小为0.01,但我想知道如何从大小为0.0的图像开始,并将其放大到1。是否只是将我

我希望在我的iphone应用程序“pop-in”中有一个图像出现在屏幕上,而不是仅仅出现在屏幕上。我所说的“弹出”是指它会从一个小点增长到实际大小。作为参考,这与Keynote中的“pop”动画效果完全相同。 我对iOS动画一无所知,因此如果有人能为我指出我需要使用的动画效果的方向,我将不胜感激

谢谢

布莱恩

更新 我根据下面的建议添加了这段代码。这是可行的,但它缩小了我的图像,而不是放大。我知道这是因为变换比例大小为0.01,但我想知道如何从大小为0.0的图像开始,并将其放大到1。是否只是将我的图像大小设置为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
                     }];

您要寻找的效果如下:

// 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
}];
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
    }

如果你想要像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”,这将仅在按钮的图像视图属性上生成动画。 希望能有帮助
一切都好。

为此,您必须使用一个简单的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];
 }

那…可能不太好用。为图像视图的帧设置动画会迫使它在动画的每一帧重新绘制自己。@NoahWitherspoon是一种更好的变换方法吗?是的。从CGAffineTransformMakeScale(0.01,0.01)到CGAffineTransformIdentity设置动画就可以了。谢谢大家的回复。我用另一个例子更新了我的问题。如何放大而不是缩小?有没有办法从不同于中心的点放大图像?是的,改变其图层的颜色
view.layer.anchorPoint=CGPointMake(0,0)
将从左上角调整视图比例
(1,1)
是它的右下角。变量图像是什么类型的对象?
图像在本例中是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];
 }