How to use NSLayoutConstraint in iOS 6?

2019-03-01 07:46发布

问题:

My app should support both iPhone resolutions (5 and older) using iOS 5 and iOS 6. When I use autolayouts in IB, on iOS 5 app crashes like this: link

So, I am trying to use NSLayoutConstraint in code, but unsuccessfully yet.

Subquestions:

  1. I am adding constraints in viewDidLoad method, but is it correct?
  2. Does updateViewConstraints invoke by framework? I have never seen that it was invoked.
  3. I tried to use examples from apple's docs, but it was without effect to view.

Anybody knows how to do it?

PS: I know it's possible to make it manually by setting frames, but I would like to use NSLayoutConstraints.

UDP: Yes, I know, that's why i use NSLayoutConstraint in code. I can make condition for determining iOS version. The question is about iOS6.

回答1:

The AutoLayout feature is only compatible with iOS6 and is not supported in iOS5. Thus the crash

If you intend your app to be compatible with iOS5, you can't use AutoLayout in your XIB files.

You can only use older methods, like the AutoResizingMask for example (which is often sufficient for most cases anyway).