LoginSignup
0
0

More than 1 year has passed since last update.

UIStackView.addArrangedSubview()のアニメーションを無効にする方法

Posted at

やりたかったこと

UIStackView上に動的にボタンを追加する処理をつくったが、表示時にうにょーんとアニメーションしてしまう。
見栄えが悪いのでやめたい。

試したこと

UIView.performWithoutAnimation {
    stackView.addArrangedSubview(view)
}

performWithoutAnimationで無効になるもんだと思ってこうやってみたが効果なし。

解決策

StackOverflowより
addArrangedSubview without animations

stackView.addArrangedSubview(view)

UIView.performWithoutAnimation {
    stackView.setNeedsLayout()
    stackView.layoutIfNeeded()
}

addArrangedSubview()の時点ではアニメーションは発生していなくてlayoutIfNeeded()による描画処理時にアニメーションしているということなのかな。

勉強になりました。

0
0
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
0
0