我发现至少 5 个其他“UIView 动画不起作用”问题,我不想再添加一个。:(。我确定这不是特定于alpha
. 的问题。与 . 相同的问题backgroundColor
。所以它是基本的。
这有效:
[self.view viewWithTag:kPlayView].alpha = 0.75;
[self.view viewWithTag:kCancelView].alpha = 0.75;
[self.view viewWithTag:kTapViewTag].backgroundColor = [UIColor whiteColor];
这没有(它什么都不做):
//kPlayView and kCancelView are subviews of kTapViewTag
[UIView animateWithDuration:2.0 animations:^{
[self.view viewWithTag:kPlayView].alpha = 0.75;
[self.view viewWithTag:kCancelView].alpha = 0.75;
[self.view viewWithTag:kTapViewTag].backgroundColor = [UIColor whiteColor];
} ];
为什么?这在kTapViewTag
视图的手势处理程序中调用。backgorundColor = [UIColor clearColor]
我想淡化为白色并将子视图的 alpha 更改为 0.75 以响应点击手势。
更新:
反向工作。这有效:
[UIView animateWithDuration:2.0 animations:^{
[self.view viewWithTag:kPlayView].alpha = 0;
[self.view viewWithTag:kCancelView].alpha = 0;
[self.view viewWithTag:kTapViewTag].backgroundColor = [UIColor clearColor];
}];
我能够在没有动画的情况下显示充当“暂停/恢复”的视图,然后为淡出设置动画。只要我不尝试为淡入设置动画,这就会来回工作。
更新 2
这是整个实现以供参考。这里有什么?(我看了太多次了)。
- (void)didTap:(id)selector
{
isPaused = (isPaused) ? NO: YES;
[self.view viewWithTag:kPlayView].userInteractionEnabled = isPaused;
[self.view viewWithTag:kCancelView].userInteractionEnabled = isPaused;
if (isPaused)
{
[self pauseLayer:self.view.layer];
[timer1 invalidate];
[timer2 invalidate];
[UIView animateWithDuration:2.0 animations:^{
[self.view viewWithTag:kPlayView].alpha = 0.75;
[self.view viewWithTag:kCancelView].alpha = 0.75;
[self.view viewWithTag:kTapViewTag].backgroundColor = [UIColor whiteColor];
} ];
}
else
{
isPaused = NO;
[UIView animateWithDuration:2.0 animations:^{
[self.view viewWithTag:kPlayView].alpha = 0;
[self.view viewWithTag:kCancelView].alpha = 0;
[self.view viewWithTag:kTapViewTag].backgroundColor = [UIColor clearColor];
}];
[self resumeLayer:self.view.layer];
[self animateNotification];
}
}
更新 3
- (void)pauseLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer convertTime:CACurrentMediaTime() fromLayer:nil];
layer.speed = 0.0;
layer.timeOffset = pausedTime;
}
- (void)resumeLayer:(CALayer*)layer
{
CFTimeInterval pausedTime = [layer timeOffset];
layer.speed = 1.0;
layer.timeOffset = 0.0;
layer.beginTime = 0.0;
CFTimeInterval timeSincePause = [layer convertTime:CACurrentMediaTime() fromLayer:nil] - pausedTime;
layer.beginTime = timeSincePause;
}