如何在iOS 6中使用NSLayoutConstraint? [英] How to use NSLayoutConstraint in iOS 6?

查看:138
本文介绍了如何在iOS 6中使用NSLayoutConstraint?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我的应用程序应支持使用iOS 5和iOS 6的iPhone分辨率(5及更早版本)。当我在IB中使用自动布局时,iOS 5应用程序崩溃如下:链接

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

所以,我试图在代码中使用NSLayoutConstraint,但还没有成功。

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

子请求:


  1. 我在viewDidLoad方法中添加约束,但它是否正确?

  2. updateViewConstraints是否通过框架调用?我从来没有见过它被调用过。

  3. 我试图使用apple的文档中的示例,但它没有效果查看。

有谁知道怎么做?

PS:我知道可以通过设置框架来手动制作,但我想使用NSLayoutConstraints。

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

UDP:是的,我知道,这就是我在代码中使用NSLayoutConstraint的原因。我可以为确定iOS版本做出条件。问题是关于iOS6。

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.

推荐答案

AutoLayout功能仅与iOS6兼容,iOS5不支持。因此崩溃

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

如果您打算将您的应用与iOS5兼容,则不能在XIB文件中使用AutoLayout。

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

您只能使用较旧的方法,例如 AutoResizingMask (对于大多数情况来说,这通常就足够了)。

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

这篇关于如何在iOS 6中使用NSLayoutConstraint?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆