LoginSignup
0
2

More than 3 years have passed since last update.

Storyboardで制約設定したViewの位置をコードで取得したい

Posted at

問題

Storyboardで制約指定したViewのframeをコードで取得したかったとき、その時点でのsizeはうまくとれているけど、originがうまくとれてなかった。
初歩的な問題かもしれないけど、はまって困った。
Viewが描画されたあとのような以下のようなときに起きてた。

func scrollViewDidEndDecelerating(_ scrollView: UIScrollView) {
  print(targetView.frame)
}

-> (0.0, 0.0, 100.0, 100.0)

結論

translatesAutoresizingMaskIntoConstraintsfalse に設定すると取得できた。

targetView.translatesAutoresizingMaskIntoConstraints = false
0
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
0
2