xcode UIImageView 缩放/淡入淡出动画?

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14620354/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-09-15 02:40:49  来源:igfitidea点击:

UIImageView Zoom/Fade animation?

iosxcodeuiimageviewjquery-animate

提问by Jon Sullivan

I want to make a little zoom/fade animation for when the UIImageView shows up in my view, I already have the code for the fade effect:

当 UIImageView 出现在我的视图中时,我想制作一些缩放/淡入淡出动画,我已经有了淡入淡出效果的代码:

    banner.alpha = 0.0;
    [UIView animateWithDuration:2.0 animations:^{
        banner.alpha = 1.0;
    }];

Now I want to know if there is another easy way to combine the fade effect with a little zoom effect, like the image becoming larger and filling up the frame as it fades in? Any ideas? Thanks!

现在我想知道是否有另一种简单的方法可以将淡入淡出效果与一点缩放效果相结合,例如图像变大并在淡入时填满框架?有任何想法吗?谢谢!

回答by Guo Luchuan

you can use CG_EXTERN CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)to do the zoom effect

你可以CG_EXTERN CGAffineTransform CGAffineTransformMakeScale(CGFloat sx, CGFloat sy)用来做缩放效果

such as

banner.alpha = 0.0;

[UIView animateWithDuration:2.0 animations:^{
    banner.alpha = 1.0;
    banner.transform =CGAffineTransformMakeScale(1.3,1.3);
}];

回答by T0m_Twt

You can also use the frame

您也可以使用框架

banner.alpha = 0;

[UIView animateWithDuration:2.0f animations:^(void){
   banner.alpha = 1.0f;
   [banner setFrame:CGRectMake(0, 0, 1024, 748)];
}];

// With Completion
[UIView animateWithDuration:0.1f animations:^(void){
   banner.alpha = 1.0f;
   [banner setFrame:CGRectMake(0, 0, 1024, 748)];
}completion:^(BOOL finished) {

}];