【问题标题】:iOS - Subview frame size inherited from parent viewiOS - 从父视图继承的子视图框架大小
【发布时间】:2015-12-26 00:50:58
【问题描述】:

我正在尝试在容器视图中设置视图。由于swipeView 内的视图有多个不同的控制器,因此必须这样做。

@IBOutlet weak var containerView: ContainerView!

override func viewDidLoad() {
    super.viewDidLoad()

     //Some other stuff

     //Create new swipeView
     var swipeView = MDCSwipeToChooseView(frame: containerView.frame, options: options)

    //Add the view from the controller to the swipeView
    swipeView.addSubview(containerViewController.view)

    //Add the swipeView to the main view
    self.view.addSubview(swipeView)

我最终得到了这个

白色区域是应该继承containerView 大小的视图。 containerView 是背景中的粉红色,并且显示正确。我注意到containerView.frame 从情节提要返回组件的大小,参见图 2。通过调用 containerView.frame 获得的框架是调整视图大小以满足所有约束之前的框架。如何获得正确的值?

【问题讨论】:

    标签: ios swift uiview uicontainerview


    【解决方案1】:

    viewDidLayoutSubviews() 中而不是viewDidLoad() 中放置相同的代码解决了这个问题。

    【讨论】:

    • 如果您正确设置每个视图的autoresizingMask,它可能也可以在viewDidLoad 中工作。
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2014-10-07
    • 2016-08-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多