2016-09-20 46 views
0

我有一个UIViewController和一个分开UIView(MyTopView),我在那个UIViewController显示。在Xcode 8,解决“选择intital设备”提示后,UIView未在该视图中正确对齐UIViewController's视图。Xcode 8:UIView不工作作为子视图

这是我的UIViewController

另外,_viewTop是一个容器视图将举行MyTopView

enter image description here

这是我UIView(MyTopView) enter image description here

ViewControllerviewWillAppear方法,

_myTopView = (MyTopView *)_viewTop; 

NSLog(@"_myTopView: %@", _myTopView); 
NSLog(@"self.view: %@", self.view); 

但它需要为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>> 

约束警告

(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)> 

我期待那的UIView将获得显示在视图控制器的视图的一部分。

它曾经用于Xcode7的ealrier版本。

回答

0

某处的UIView(MyTopView)初始化,在指定init -method优选期间,设置其translatesAutoresizingMaskIntoConstraints -property到false/NO

Ex。

- (instancetype) initWithCoder: (NSCoder*) aCoder 
{ 
    if (!(self = [super initWithCoder: aCoder])) return nil; 

    self.translatesAutoresizingMaskIntoConstraints = NO; 

    return self; 
}