Adding View Programatically With Auto Layout Gives 'NSGenericException', reason: 'Unable to install constraint on view

后端 未结 3 1567
暖寄归人
暖寄归人 2021-02-09 18:37

I am adding a view as a subview using [self.view addSubview:myView]. This works fine in portrait mode. However, it doesn\'t work at all in landscape. How do I add l

3条回答
  •  無奈伤痛
    2021-02-09 18:59

    There are few things about Auto layouts. When ever you add layout constraints make sure it is not ambiguous. Ambiguous layout would result in undefined behaviour in your display. So good idea is to use IB which will never allow you to create a ambiguous layout, but you got to go through all the constraints to make sure they are valid.

    If you want to do it programatically I would suggest you to use Visual language.

    It will be helpful to go though these tips before using layout.

提交回复
热议问题