12
9

More than 3 years have passed since last update.

UIViewのisHiddenをアニメーション化する

Last updated at Posted at 2020-01-08

業務で少しハマったのでメモ。

問題点

API通信成功時のみ、View(仮にmainViewとする)内のコンテンツを表示させたかった。
mainViewの上にemptyViewという別のViewを載せ、API通信成功後、Bをフェードアウトさせるようにしたい。

emptyView.isHidden = true

isHiddenプロパティはアニメーションしないため、API通信成功後などにemptyViewを消そうとすると、見た目上、突然emptyViewが消滅したかのように見えてしまう。

解決方法

UIView.animateを使った実装にして、alpha値でフェードアウトするように見せた。

UIView.animate(withDuration: 0.3, animations: {
     self.emptyView.alpha = 0
}, completion:  { _ in
       self.emptyView.isHidden = true
})

参考URL

12
9
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
12
9