自动版式抱怨没有国界2 UITextFields限制 [英] AutoLayout complains about constraints for 2 UITextFields with no borders

查看:115
本文介绍了自动版式抱怨没有国界2 UITextFields限制的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想建立一个只有2文本域,以及2个按钮登录我的看法。所以x code适用相应的约束在我的故事板LoginViewController所有元素我申请了添加缺少的约束属性。我限制我的应用程序只在纵向模式下运行,所以我使用的是wCompact hRegular设置。

I am trying to build my login view that has only 2 TextFields, and 2 buttons. I am applying the "Add Missing Constraints" property so that Xcode applies the corresponding constraints to all the elements in my LoginViewController in the storyboard. I am restricting my app to run only in portrait mode, so I am using the "wCompact hRegular" setup.

每当我跑我的应用程序和过渡到我的LoginViewController与SEGUE,我的应用程序只能显示一个文本框,并显示出一堆关于自动布局控制台的错误。

Whenever I run my app and transition to my LoginViewController with a segue, my app displays only one textfield, and shows a bunch of errors in the console regarding autolayout.

我想实现的功能是要拿出类似于新解析登录界面登录屏幕。也就是说有两个文本框,没有国界,只有这样显示的用户名文本框的底部边框可以从文本框密码划分它,像这样:

The functionality I am trying to achieve is to come up with a login screen that resembles the new Parse login screen. That is having two textfields with no borders and only the bottom border of the username textfield showing so it can divide it from the password textfield, like so:

到目前为止,这是我的应用程序在运行时的样子:

So far, this is how my app looks when it runs:

和它看起来应该是这样的:

And it should look like this:

下面是出现在控制台中的错误:

Here's the error that appears in the console:

2015-06-14 20:40:21.480 MyApp[71158:3600335] Unable to simultaneously satisfy constraints.
    Probably at least one of the constraints in the following list is one you don't want. Try this: (1) look at each constraint and try to figure out which you don't expect; (2) find the code that added the unwanted constraint or constraints and fix it. (Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints) 
(
    "<_UILayoutSupportConstraint:0x7f9ff3f6d260 V:[_UILayoutGuide:0x7f9ff3f7a140(20)]>",
    "<_UILayoutSupportConstraint:0x7f9ff3f087a0 V:|-(0)-[_UILayoutGuide:0x7f9ff3f7a140]   (Names: '|':UIView:0x7f9ff3f7a030 )>",
    "<_UILayoutSupportConstraint:0x7f9ff3f24730 V:[_UILayoutGuide:0x7f9ff3f7a2a0(0)]>",
    "<_UILayoutSupportConstraint:0x7f9ff3f71640 _UILayoutGuide:0x7f9ff3f7a2a0.bottom == UIView:0x7f9ff3f7a030.bottom>",
    "<NSLayoutConstraint:0x7f9ff3f6b9e0 V:[UITextField:0x7f9ff3f782a0]-(NSSpace(8))-[UITextField:0x7f9ff3f7a3d0]>",
    "<NSLayoutConstraint:0x7f9ff3f58a40 V:[UIButton:0x7f9ff3f7ab00'Login']-(331)-[_UILayoutGuide:0x7f9ff3f7a2a0]>",
    "<NSLayoutConstraint:0x7f9ff3f28b60 V:[_UILayoutGuide:0x7f9ff3f7a140]-(237)-[UITextField:0x7f9ff3f782a0]>",
    "<NSLayoutConstraint:0x7f9ff3f34180 V:[UIButton:0x7f9ff3f7ad20'I forgot my password']-(49)-[UIButton:0x7f9ff3f7ab00'Login']>",
    "<NSLayoutConstraint:0x7f9ff3f341d0 V:[UITextField:0x7f9ff3f7a3d0]-(35)-[UIButton:0x7f9ff3f7ad20'I forgot my password']>",
    "<NSLayoutConstraint:0x7f9ff3f29f90 V:[UITextField:0x7f9ff3f782a0(30)]>",
    "<NSLayoutConstraint:0x7f9ff3f055a0 V:[UIButton:0x7f9ff3f7ad20'I forgot my password'(30)]>",
    "<NSLayoutConstraint:0x7f9ff3f055f0 V:[UIButton:0x7f9ff3f7ab00'Login'(30)]>",
    "<NSLayoutConstraint:0x7f9ff3cc3b80 'UIView-Encapsulated-Layout-Height' V:[UIView:0x7f9ff3f7a030(667)]>"
)

Will attempt to recover by breaking constraint 
<NSLayoutConstraint:0x7f9ff3f055f0 V:[UIButton:0x7f9ff3f7ab00'Login'(30)]>

Make a symbolic breakpoint at UIViewAlertForUnsatisfiableConstraints to catch this in the debugger.
The methods in the UIConstraintBasedLayoutDebugging category on UIView listed in <UIKit/UIView.h> may also be helpful.

有谁知道如何解决这个问题,为什么它不工作?我甚至尝试手动手动添加所有的约束,但没有奏效。另外,如果我给我的文本框的边框圆润,使他们比故事板的整个宽度小了一点,它做什么,它是预料之中的事。

Does anyone know how to fix this and why it does not work? I even tried manually adding all the constraints manually, but it did not work. Also, if I give my textfields rounded borders and make them a little smaller than the storyboard's full width, it does what it's expected to do.

感谢您为您提前帮助。

干杯!

推荐答案

添加缺少的约束并不总是一个好主意,添加constraints..rather你应该总是preFER手动添加约束...

"Add Missing Constraints" is not always a good idea to add constraints..rather you should always prefer to add constraints manually...

下面是你的UI图像...我用 wAnyhAny 的布局,因为它是添加约束通用设备很好的做法...

Here is the image for your UI...I used wAnyhAny layout as it is good practice for add constraints for universal devices...

我用简单的宽度约束为文本框,而你应该等宽超级视图,并添加乘数根据设备宽度来调整宽度

I used simply width constraint for textfield, rather you should Equal width to super view and add multiplier to resize width according to device width

下面是输出图像中的不同的尺寸...

Here is the output image in different sizes...

这篇关于自动版式抱怨没有国界2 UITextFields限制的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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