iOS – animation效果 – 图像popup

我想在我的iPhone应用程序“popup”在屏幕上的图像,而不是只是出现。 “stream行”是指从一个小点到实际尺寸。 作为参考,这与Keynote中的“stream行”animation效果完全相同。 我对iOSanimation完全陌生,所以如果有人能指出我需要使用的animation效果的方向,那将不胜感激。

谢谢

布赖恩

更新我从下面的build议中添加了这个代码。 这有效,但它缩小了我的形象,而不是起来。 我知道这是因为我有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]; 

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

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

如果你想像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 }]; }]; }];} 

当你想animation视图时调用这个方法

如果你有button上的文字和图像,你只是想animation的button的图像,然后只是用“btn.imageView”replace“btn”,这只会产生button的图像视图属性的animation。 希望它有所帮助一切顺利。

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

因此,例如,从您的视图开始,将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 }]; 

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 } 

为此,你将不得不使用一个简单的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]; }