iOS-UIimageView缩放动画不起作用

时间:2012-12-21 07:39:43

标签: iphone objective-c ios imageview

我想创建一个动画,使imageView变得越来越小和透明,然后消失。我试过下面的代码,它不起作用,运行时它将从0.01大小增长到原始大小。我无法弄清楚问题出在哪里。

非常感谢!

[UIView animationWithDuration:2 animations:^{
[imageview setTransform:(CGAffineTransformMakeScale(0.01,0.01))];
[imageview setAlpha:0];
}
completion:^(BOOL finished){
[imageview removeFromSuperview];
}];

2 个答案:

答案 0 :(得分:0)

试试这段代码:

[UIView animationWithDuration:2 animations:^{
CGAffineTransform *transform =  CGAffineTransformScale(imageView.transform, 0.01, 0.01);
[imageview setTransform:transform];
[imageview setAlpha:0];
}
completion:^(BOOL finished){
[imageview removeFromSuperview];
}];

这将考虑现有的imageView转换。 (您是否有可能已将变换应用于此imageView?)

您可以尝试的另一件事是添加:UIViewAnimationOptionBeginFromCurrentState 作为动画方法的一个选项。您将不得不使用:

+ (void)animateWithDuration:(NSTimeInterval)duration delay:(NSTimeInterval)delay options:(UIViewAnimationOptions)options animations:(void (^)(void))animations completion:(void (^)(BOOL finished))completion{

}

答案 1 :(得分:0)

实际上,您的方法名称似乎不正确。正确的方法是 animateWithDuration

[UIView animateWithDuration:2 animations:^{