我目前正在制作一个具有复杂加载屏幕的应用程序。我已经使用UI Animation创建了加载器,但想要添加一个加载栏完成后将出现的按钮。我遇到过将按钮隐藏一段时间或在一定时间后出现的想法。在一段时间后显示/隐藏按钮
如何在一段时间后显示/隐藏按钮?
我目前正在制作一个具有复杂加载屏幕的应用程序。我已经使用UI Animation创建了加载器,但想要添加一个加载栏完成后将出现的按钮。我遇到过将按钮隐藏一段时间或在一定时间后出现的想法。在一段时间后显示/隐藏按钮
如何在一段时间后显示/隐藏按钮?
使用NSTimer应该是最简单的方法。
你可以调用你的方法来显示的一段时间后,该按钮:
[self performSelector:@selector(showButton) withObject:nil afterDelay:0.5];
或者,可能会更好,如果你想动画按钮的外观,你都可以做动画,单次通话中的延迟,例如假设按钮本来具有的0.0的α:
[UIView animateWithDuration:0.25
delay:0.5
options:nil
animations:^{
myButton.alpha = 1.0;
}
completion:^(BOOL finished){
// if you want to do anything when animation is done, do it here
}
];
创建的NSTimer做到这一点,
enter code here
定时器= [的NSTimer scheduledTimerWithTimeInterval:5目标:自选择器:@selector(hideButton :) USERINFO:无重复:NO];
enter code here
- (无效)hideButton:(的UIButton *)hideButton {
enter code here
hideButton.hidden=TRUE;
}