0
1

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 3 years have passed since last update.

scrollViewの中のViewにaddSubViewで追加されたViewをスクロールしたい

Last updated at Posted at 2021-02-04

ScrollViewを作成

Viewを作成

この時のイメージはScrollViewのなかにがViewが入ってます。

ScrollViewとViewは上下左右Autoレイアウトを0で設定。

そしてScrollViewの中のContaint Layout GuideとViewをCenter Vertically in Content Guideで結びます。

次にScrollViewの中のFrame Layout GuideとViewをEqual widthで結びます。

そしてコードはこちら。

    containerView.frame.size.height = view.frame.size.height

containerViewがScrollViewの中のView

viewがaddSubViewしたビューです。

この時

    containerView.frame.size.height = view.frame.size.height

上記の場合だと表示はできますが、ScrollViewはスクロールできません。

なので、scrollViewの中のViewにaddSubViewで追加されたViewをスクロールしたい場合は

    containerView.frame.size.height = view.frame.size.height

上記を使いましょう。

もしかするとそれだけでは動かない可能性があります。

その時はこれを使ってください。

    containerView.translatesAutoresizingMaskIntoConstraints = true

すると動くかなと思います。

参考記事

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

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?