我有一个自定义视图(绘制标注/气泡),我目前将其添加为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的自定义子视图。
任何帮助表示感谢。
答案 0 :(得分:0)
试试这个。
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];
答案 1 :(得分:0)
更好地使用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];