gpt4 book ai didi

ios - 动画不适用于 UIImageView

转载 作者:行者123 更新时间:2023-11-29 12:08:07 25 4
gpt4 key购买 nike

我添加了一个 UIImageView 作为 subview 。我正在尝试使用变换对其进行动画处理。动画没有,但是 ImageView 已正确缩放,只是没有自动反转。我做错了什么吗?

UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
iv_tap.center = point;
iv_tap.tag = 779;
iv_tap.hidden = true;
[UIView animateWithDuration:2.0
delay:.05
options: UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat | UIViewAnimationOptionCurveLinear
animations:^{
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);
}
completion:NULL];


[self addSubview:iv_tap];

最佳答案

imageView 添加到 view 后,您需要制作动画。如果您在 addSubView 之前执行动画, ImageView 不在 View 层次结构中,您看不到任何动画。

 UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self.view addSubview:iv_tap]; //this could be self in your case
iv_tap.tag = 779;

[UIView animateWithDuration:2.0 delay:0.05 options:UIViewAnimationOptionCurveEaseOut animations:^{

iv_tap.center=self.view.center;
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);

[self.view layoutIfNeeded]; //this could be self in your case

} completion:^(BOOL finished) {
//do your stuff when animation is done
}];

如果您正在子类化 UIView,那么您甚至可以将它放在 drawRect 方法中:

UIImageView * iv_tap = [[UIImageView alloc] initWithImage:[UIImage imageNamed:@"gesture_tap"]];
[self addSubview:iv_tap];
iv_tap.tag = 779;

[UIView animateWithDuration:2.0 delay:0.05 options:UIViewAnimationOptionCurveEaseOut animations:^{

iv_tap.center=self.center;
iv_tap.transform = CGAffineTransformScale(CGAffineTransformIdentity, 1.8, 1.8);

[self layoutIfNeeded];

} completion:^(BOOL finished) {
//do your stuff when animation is done
}];

关于ios - 动画不适用于 UIImageView,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34363248/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com