2

Since the iOS update to 13 my app is unfortunately behaving bad. The containers height is controlled by the UISegmentControl element. The hook works fine and the correct index is set. There are 3 subcontainers:

  • profileDataContainerView
  • addValueContainerView
  • checkInHistoryContainerView

Unfortunately the containers within the main scrollview dont change their height. Does anyone know the solution for this issue?

@IBAction func showComponent(_ sender: UISegmentedControl) {
    showComponent(index: sender.selectedSegmentIndex)
}

private func showComponent(index: Int) {
    currentContainer?.bounds.size.height = 0
    currentSegmentedControllerIndex = index
    switch index {
    case 0:
        profileDataContainerView.bounds.size.height = 308
        currentContainer = profileDataContainerView
    case 1:
        addValueContainerView.bounds.size.height = 294
        currentContainer = addValueContainerView
    case 2:
        if let tableView = checkInHistoryContainerView.subviews.last as? UITableView {
            checkInHistoryContainerView.bounds.size.height = tableView.contentSize.height
        }
        currentContainer = checkInHistoryContainerView
    default:
        break
    }
    updateContentHeight()
}

How it looks in the storyboard

AndacAydin
  • 1,416
  • 19
  • 26

3 Answers3

1

You can use yourview.layer.bounds instead of yourview.bounds.

0

It's because it's a struct.

this will work

myView.frame = Frame(....)

this will not

myView.bounds.height = someNumber
Chris
  • 1,539
  • 13
  • 25
  • Hi Chris, I tried currentContainer?.frame = CGRect(origin: currentContainer?.frame.origin ?? scrollView.frame.origin, size: CGSize(width: 0, height: 0)) But this doesnt change the height to 0. Did I do it wrong? (Frame was not recognized by the ide, seems like its gone in swift4 ?) – AndacAydin Oct 16 '19 at 18:58
0

It is hard to say for sure why your app is not working with just the code provided, but you can keep in mind a few things.

  1. A scroll view size is adjusted automatically by its content. Try adjusting the scrollview itself, see this link: how to set scrollview content size in swift 3.0

  2. Adjust the content size and then reload the view afterwards. Try to make sure that your app is loading all of your views after you set the new size. This link may help you with changing frame sizes: Change frame programmatically with auto layout

In general storyboards are a disaster for things like this if you aren't careful. Storyboards tend to give the illusion of success when in fact the constraints are wrong.

One final thing to check (a bug I found within my code) is that segues have changed substantially, so make sure that your segues are the correct type and you are presenting in the way you want to. Here is a link on some of the presenting changes in iOS 13: https://medium.com/@hacknicity/view-controller-presentation-changes-in-ios-13-ac8c901ebc4e

Edit: Chris replied mentioning that you are using a struct, if thats the case then they are correct in that you are not properly changing the value.

ekrenzin
  • 387
  • 2
  • 12