ios - 获取自动布局、自动布局、 Objective-C 的警告

标签 ios objective-c autolayout nslayoutconstraint

<分区>

我的目标:在 View 中将指示器(垂直和水平)居中放置在按钮上

我正在做的是:

[self.logInButton addConstraint:[NSLayoutConstraint constraintWithItem:spinner1
                                                             attribute:NSLayoutAttributeCenterY
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.logInButton
                                                             attribute:NSLayoutAttributeCenterY
                                                            multiplier:1.0
                                                              constant:0]];
[self.logInButton addConstraint:[NSLayoutConstraint constraintWithItem:spinner1
                                                             attribute:NSLayoutAttributeCenterX
                                                             relatedBy:NSLayoutRelationEqual
                                                                toItem:self.logInButton
                                                             attribute:NSLayoutAttributeCenterX
                                                            multiplier:1.0
                                                              constant:0]];
self.logInButton addSubView:spinner

但是,我在下面收到警告

The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x17e19390 UIActivityIndicatorView:0x17d035d0.centerY == UIButton:0x17df4430.centerY>
    When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.
2013-06-12 17:37:19.610 FlipGive[366:60b] The view hierarchy is not prepared for the constraint: <NSLayoutConstraint:0x17e19810 UIActivityIndicatorView:0x17d035d0.centerX == UIButton:0x17df4430.centerX>
    When added to a view, the constraint's items must be descendants of that view (or the view itself). This will crash if the constraint needs to be resolved before the view hierarchy is assembled. Break on -[UIView _viewHierarchyUnpreparedForConstraint:] to debug.

有谁知道我在这里做错了什么?请帮忙

欢迎所有评论。谢谢

最佳答案

您需要在添加约束之前添加 View 。

先放这个再加约束

self.logInButton addSubView:spinner

关于ios - 获取自动布局、自动布局、 Objective-C 的警告,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17075853/

相关文章:

iphone - Transient sectionNameKeyPath & NSSortDescriptor NSFetchedResultsController

objective-c - 防止 NSTimer 在后台应用程序中触发延迟

ios - 无法同时满足约束自定义 header 部分

iOS 8 自定义键盘 : Changing the height without warning 'Unable to simultaneously satisfy constraints...'

ios - iPhone In App Purchase 提示在新用户的全新设备上登录 addTransactionObserver

ios - 将视频合并在一起(AVFoundation)

iOS5 Facebook 整合

iphone - Objective-c 中 iPhone 上的 HTML 实体编码(将 '<' 转换为 '&lt;')

ios - 我无法使用自动布局

ios - 在 iOS 的 tableView 中插入新行