1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 5 years have passed since last update.

iOSで遅延処理

Posted at

iOS(Swift4)以上で遅延処理を行う場合についてのまとめ。

単純に処理を遅延させたい

DispatchQueueのasyncAfterを利用。

DispatchQueue.main.asyncAfter(deadline: .now() + 2.0) {
    // 2.0秒後に実行したい処理
}

アニメーションが絡む処理を遅延させたい

UIView.animateを利用。


UIView.animate(withDuration: 1.0, delay: 2.0, options: .autoreverse, animations: {
    // 2.0秒後に実行したいアニメーション処理
}, completion: { _ in
    // アニメーション終了後に実行したい処理
})
  • withDuration: アニメーションの実行時間
  • delay: 遅延時間
  • option: アニメーション動作の種類 UIView.AnimationOptions
  • animations: アニメーション処理
  • completion: アニメーション完了後処理 (nilでもOK)

※UIView.AnimationOptionsの種類:
https://developer.apple.com/documentation/uikit/uiview/animationoptions

参考

公式ドキュメント

参考サイト

1
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?