iPhone ゲームの通知システムに取り組んでおり、画像が画面にポップアップ表示され、2 秒後に自動的にフェードアウトするようにしたいと考えています。
- ユーザーがメソッド「popupImage」を呼び出すボタンをクリックする
- 画面上の指定された場所に画像が表示されます。フェードインする必要はありません
- 画面に 2 秒間表示された後、画像は自動的にフェードアウトします。
これを行う方法はありますか?ありがとうございます。
UIView
そのためには専用のメソッドを使用してください。
したがってUIImageView
、すでに準備ができており、作成済みでメイン ビューに追加されているが、単に非表示になっていると想像してください。あなたのメソッドは単にそれを見えるようにし、その「アルファ」プロパティを 1.0 から 0.0 (0.5 秒のアニメーションの間) にアニメーション化することによって、2 秒後にアニメーションを開始してフェードアウトする必要があります:
-(IBAction)popupImage
{
imageView.hidden = NO;
imageView.alpha = 1.0f;
// Then fades it away after 2 seconds (the cross-fade animation will take 0.5s)
[UIView animateWithDuration:0.5 delay:2.0 options:0 animations:^{
// Animate the alpha value of your imageView from 1.0 to 0.0 here
imageView.alpha = 0.0f;
} completion:^(BOOL finished) {
// Once the animation is completed and the alpha has gone to 0.0, hide the view for good
imageView.hidden = YES;
}];
}
そのような単純な!
スイフト2
self.overlay.hidden = false
UIView.animateWithDuration(2, delay: 5, options: UIViewAnimationOptions.TransitionFlipFromTop, animations: {
self.overlay.alpha = 0
}, completion: { finished in
self.overlay.hidden = true
})
スイフト 3、4、5
self.overlay.isHidden = false
UIView.animate(withDuration: 2, delay: 5, options: UIView.AnimationOptions.transitionFlipFromTop, animations: {
self.overlay.alpha = 0
}, completion: { finished in
self.overlay.isHidden = true
})
overlay
私のイメージの出口はどこですか。
はいあります。ここUIView
でブロックベースのアニメーションを見てください。そして例のためにグーグル。
+ (void)animateWithDuration:(NSTimeInterval)duration animations:(void (^)(void))animations
タイマーを開始することもできます
+ (NSTimer *)scheduledTimerWithTimeInterval:(NSTimeInterval)seconds target:(id)target selector:(SEL)aSelector userInfo:(id)userInfo repeats:(BOOL)repeats