私は現在、複雑なロード画面を持つアプリを作成しています。UIアニメーションを使用してローダーを作成しましたが、読み込みバーが終了すると表示されるボタンを追加したいと思います。ボタンを一定期間非表示にしたり、一定期間後に表示したりするというアイデアに出くわしました。
一定期間後にボタンを表示/非表示にするにはどうすればよいですか?
メソッドを呼び出して、一定期間後にボタンを表示することができます。
[self performSelector:@selector(showButton) withObject:nil afterDelay:0.5];
または、ボタンの外観をアニメーション化する場合は、アニメーションと遅延の両方を1回の呼び出しで実行できます。たとえば、ボタンのアルファが元々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 を使用するのが最も簡単な方法です。
それを行うためにNSTimerを作成し、
Timer = [NSTimer scheduledTimerWithTimeInterval:5 target:self selector:@selector(hideButton:) userInfo:nil repeats:NO];
-(void)hideButton:(UIButton *)hideButton {
if hideButton.isHidden == false {
hideButton.hidden=TRUE;
} else {
hideButton.hidden = FALSE
}