我有一个警报屏幕,可以控制亮度和其他东西。以下是我试图用它完成的事情:
我有一个黑色scrim
覆盖屏幕上的所有元素,我在没有用户交互5秒后从alpha 1到0进行动画制作。当轻触它时,它应该从alpha 0动画到1并隐藏,这样我就可以与它下面的控件进行交互。然后在不活动5秒后再次,稀松布应该再次从0到1动画。当用户点击它时,稀松布应该隐藏和取消隐藏。
现在我正在使用animateWithDuration
让所有动画正常运行,但在每个动画完成时为alpha 0,稀松布不会隐藏,因此我无法访问下面的控件。如果scrim
的alpha值为0,我怎样才能以不妨碍屏幕控制的方式完成这些动画?
这是我的代码:
- (void)viewDidLoad {
[super viewDidLoad];
UITapGestureRecognizer *tapGesture = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(hideScrim)];
tapGesture.cancelsTouchesInView = NO;
[self.scrim addGestureRecognizer:tapGesture];
}
-(void)viewDidAppear:(BOOL)animated {
[self showScrim];
}
-(void)showScrim {
self.scrim.alpha = 0.0;
self.scrim.hidden = NO;
[UIView animateWithDuration:0.50 delay:5.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.scrim.alpha = 1.0;
} completion:^(BOOL finished) {
}];
}
-(void)hideScrim
{
[UIView animateWithDuration:0.50 animations:^{
self.scrim.alpha = 1.0;
} completion:^(BOOL finished) {
self.scrim.hidden = YES;
[self showScrim];
}];
}
答案 0 :(得分:0)
将隐藏方法更新为
-(void)hideScrim
{
[UIView animateWithDuration:0.50 animations:^{
self.scrim.alpha = 1.0;
} completion:^(BOOL finished) {
self.scrim.hidden = YES;
[self performSelector:@selector(showScrim) withObject:nil afterDelay:5];//if you want to show again after 5 seconds
}];
}
并显示方法
-(void)showScrim {
self.scrim.alpha = 0.0;
self.scrim.hidden = NO;
[UIView animateWithDuration:0.50 delay:0.0 options:UIViewAnimationOptionCurveEaseIn animations:^{
self.scrim.alpha = 1.0;
} completion:^(BOOL finished) {
}];
}
如果您最初需要延迟播放,请尝试以下代码
self.scrim.hidden = YES;
[self performSelector:@selector(showScrim) withObject:nil afterDelay:5];