【问题标题】:setting bounds.height in ios 13 not working anymore在 ios 13 中设置 bounds.height 不再起作用
【发布时间】:2019-10-15 20:52:26
【问题描述】:

不幸的是,自从 iOS 更新到 13 后,我的应用表现不佳。 容器高度由 UISegmentControl 元素控制。 钩子工作正常并设置了正确的索引。 有3个子容器:

  • profileDataContainerView
  • addValueContainerView
  • checkInHistoryContainerView

不幸的是,主滚动视图中的容器没有改变它们的高度。 有谁知道这个问题的解决方案吗?

@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()
}

【问题讨论】:

    标签: ios swift ios13


    【解决方案1】:

    您可以使用 yourview.layer.bounds 代替 yourview.bounds。

    【讨论】:

    • 酷。这有帮助:)
    【解决方案2】:

    因为它是一个结构体。

    这会起作用

    myView.frame = Frame(....)
    

    这不会

    myView.bounds.height = someNumber
    

    【讨论】:

    • 嗨,克里斯,我试过 currentContainer?.frame = CGRect(origin: currentContainer?.frame.origin ?? scrollView.frame.origin, size: CGSize(width: 0, height: 0)) 但是这不会将高度更改为 0。我做错了吗? (框架没有被 ide 识别,好像它在 swift4 中消失了?)
    【解决方案3】:

    很难确定为什么您的应用程序不能仅使用提供的代码,但您可以记住一些事情。

    1. 滚动视图的大小会根据其内容自动调整。尝试调整滚动视图本身,请参阅此链接:how to set scrollview content size in swift 3.0

    2. 调整内容大小,然后重新加载视图。设置新大小后,请尝试确保您的应用正在加载所有视图。此链接可以帮助您更改帧大小:Change frame programmatically with auto layout

    一般来说,如果你不小心的话,故事板对于这样的事情来说是一场灾难。故事板往往给人一种成功的假象,而实际上约束是错误的。

    最后要检查的一件事(我在代码中发现的一个错误)是转场发生了重大变化,因此请确保您的转场是正确的类型,并且以您想要的方式呈现。以下是 iOS 13 中一些呈现变化的链接: https://medium.com/@hacknicity/view-controller-presentation-changes-in-ios-13-ac8c901ebc4e

    编辑:克里斯回复说您正在使用结构,如果是这样,那么它们是正确的,因为您没有正确更改值。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2022-01-22
      • 2020-01-24
      相关资源
      最近更新 更多