[英]Xcode 8: UIView is not working as Subview
I have a UIViewController
and a seprate UIView(MyTopView)
which I am showing on that UIViewController
. 我有一个UIViewController
和一个UIView(MyTopView)
,它们正在该UIViewController
上显示。 In Xcode 8
, after resolving that "Choose intital device" prompt the UIView
is not aligning properly in that UIViewController's
View. 在Xcode 8
,解决了“选择初始设备”提示后, UIView
在该UIViewController's
View中未正确对齐。
This is my UIViewController
. 这是我的UIViewController
。
Also, _viewTop is a container view which will hold MyTopView 另外,_viewTop是一个容器视图,它将保存MyTopView
And this is my UIView
(MyTopView) 这是我的UIView
(MyTopView)
In ViewController
, viewWillAppear
method, 在ViewController
viewWillAppear
方法中,
_myTopView = (MyTopView *)_viewTop;
NSLog(@"_myTopView: %@", _myTopView);
NSLog(@"self.view: %@", self.view);
But it takes incorrect frame for UIView
(MyTopView) 但是UIView
(MyTopView)的框架不正确
_myTopView: <MyTopView: 0x7f9f5b5089f0; frame = (0 0; 625 832); autoresize = RM+BM; layer = <CALayer: 0x6080002230c0>>
self.view: <UIView: 0x7f9f5b5084f0; frame = (0 0; 414 736); autoresize = W+H; layer = <CALayer: 0x608000223080>>
Constraints warning 约束警告
(Note: If you're seeing NSAutoresizingMaskLayoutConstraints that you don't understand, refer to the documentation for the UIView property translatesAutoresizingMaskIntoConstraints)
(
"<NSAutoresizingMaskLayoutConstraint:0x608000089560 h=-&- v=-&- UIView:0x7fc4c0408da0.height == MyTopView:0x7fc4c0604780.height - 832 (active)>",
"<NSLayoutConstraint:0x608000088a20 V:|-(20)-[UIView:0x7fc4c0409c90] (active, names: '|':UIView:0x7fc4c0408da0 )>",
"<NSLayoutConstraint:0x608000088ed0 V:[UIView:0x7fc4c0409c90]-(20)-| (active, names: '|':UIView:0x7fc4c0408da0 )>",
"<NSLayoutConstraint:0x608000087df0 MyTopView:0x7fc4c0604780.height == 150 (active)>"
)
Will attempt to recover by breaking constraint
<NSLayoutConstraint:0x608000088ed0 V:[UIView:0x7fc4c0409c90]-(20)-| (active, names: '|':UIView:0x7fc4c0408da0 )>
I was expecting that UIView will get displayed in that ViewController's View part. 我期望UIView会显示在该ViewController的View部分中。
It did used to work on ealrier version of Xcode7. 它确实曾经在Xcode7的早期版本上工作。
Somewhere during initialisation of UIView(MyTopView)
, preferable in the designated init
-method, set its translatesAutoresizingMaskIntoConstraints
-property to false
/ NO
. 在UIView(MyTopView)
初始化期间的某个位置UIView(MyTopView)
最好是在指定的init
方法中),将其translatesAutoresizingMaskIntoConstraints
-property设置为false
/ NO
。
Ex. 例如
- (instancetype) initWithCoder: (NSCoder*) aCoder
{
if (!(self = [super initWithCoder: aCoder])) return nil;
self.translatesAutoresizingMaskIntoConstraints = NO;
return self;
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.