[英]UIView block animation not working
我有一个自定义视图(绘制标注/气泡),该视图当前作为子视图添加到UIImageView。 它可以按预期工作,但我想给该操作赋予类似弹簧的效果。 我正在使用下面的代码,但它不起作用(该块被执行但没有动画):
/* ViewController */
UIImageView *iv = self.imageView;
ZGCBubbleView *bubbleView = [[ZGCBubbleView alloc] init];
bubbleView.hidden = YES;
[iv addSubview:bubbleView];
// UIView animation test
[UIView animateWithDuration:2.0
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0.5
options:UIViewAnimationOptionAllowAnimatedContent & UIViewAnimationOptionLayoutSubviews
animations:^{
bubbleView.hidden = NO;
[self.view layoutIfNeeded]; // tried this
}
completion:nil];
我试图为隐藏属性和alpha属性设置动画,但结果相同。 我也尝试过动画addSubview方法,没有区别。 我从一个更简单的动画开始作为概念验证,但是那也不起作用。
上面的代码是在(void)viewDidAppear:(BOOL)动画周期内调用的方法中执行的。 这与动画是否在主线程中执行有关吗? 我已经读过一些关于这种效果的内容,但不确定。 另外,我正在为UIImageView使用自动布局,但是在这种情况下,这并不重要,因为动画已应用于UIImageView的自定义子视图。
任何帮助表示赞赏。
试试这个。
UIButton *catchButton = (UIButton *)sender;
[UIView animateWithDuration:1.0
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut//UIViewAnimationOptionAutoreverse | UIViewAnimationOptionRepeat |
animations:^{
catchButton.alpha = 0.4;
catchButton.enabled = NO;
}
completion:NULL];
更好地使用Alpha。
UIImageView *iv = self.imageView;
ZGCBubbleView *bubbleView = [[ZGCBubbleView alloc] init];
bubbleView.alpha = 0;
// bubbleView.hidden = YES;
[iv addSubview:bubbleView];
// UIView animation test
[UIView animateWithDuration:2.0
delay:0
usingSpringWithDamping:0.5
initialSpringVelocity:0.5
options:UIViewAnimationOptionAllowAnimatedContent & UIViewAnimationOptionLayoutSubviews
animations:^{
// bubbleView.hidden = NO;
bubbleView.alpha = 1;
//[self.view layoutIfNeeded]; // tried this
}
completion:nil];
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.