UIButtons at the bottom of UIScrollView not working

后端 未结 6 816
囚心锁ツ
囚心锁ツ 2020-12-29 05:02

I created a UIScrollView in my storyboards and have added 12 UIButtons in a container View which is inside the UIScrollView.

when running on the iPhone 5s simulator,

6条回答
  •  滥情空心
    2020-12-29 05:53

    Another option is to reduce the priority on the Content View.Center Y constraint.

    In Xcode 9, I laid out the contentView as needed and the button extended below the view on the iPhone 5. I dynamically resized the scrollView.contentSize.height and contentView.frame in the view controller. The scrollView scrolled for me but I was still unable to select the button and was seeing warnings in the Storyboard.

    Once I lowered the priority on the Center Y Alignment Constraint for the contentView, the warnings in Storyboard disappeared and I was able to scroll to the bottom of the scrollView and select the button on the iPhone 5 simulator.

    NOTE: I'm still checking the device size and resizing the scrollView.contentSize.height value in viewWillLayoutSubviews() for small devices.

    override func viewWillLayoutSubviews() {
            super.viewWillLayoutSubviews()
            scrollView.contentSize.height = (UIDevice.current.isSmallDevice) ? 560 : contentView.frame.size.height
        }
    

    (UIDevice.current.isSmallDevice is a call to an extension of UIDevice that returns a bool determined by screen size)

提交回复
热议问题