我有一个MenuViewController
,在viewController
里面我有两个childViewControllers,第一个在左边,第二个在右边。
VIEW_WIDTH = self.view.frame.size.width;
WIDTH_ListTableView = 0.4;
ListViewController *listViewController = [[ListViewController alloc] init];
ListNavigationViewController *listViewNavigation = [[ListNavigationViewController alloc] initWithRootViewController:listViewController];
[self addChildViewController:listViewNavigation];
[self.view insertSubview:listViewNavigation.view belowSubview:self.searchBarView.view];
[listViewNavigation didMoveToParentViewController:self];
listViewNavigation.view.frame = CGRectMake(0,
y,
VIEW_WIDTH*WIDTH_ListTableView,
height);
PreViewViewController *readViewController = [[PreViewViewController alloc] init];
[self addChildViewController:readViewController];
[self.view insertSubview:readViewController.view belowSubview:listViewNavigation.view];
[readViewController didMoveToParentViewController:self];
readViewController.view.frame = CGRectMake(listViewNavigation.view.frame.origin.x + listViewNavigation.view.frame.size.width,
listViewNavigation.view.frame.origin.y,
VIEW_WIDTH - listViewNavigation.view.frame.size.width,
listViewNavigation.view.frame.size.height);
但我无法更改readViewController
的框架,其宽度和高度始终为(768.0,1024.0)。
我为listViewNavigation添加了约束,但 listViewNavigation.view.y = 0
- (void)addConstraintWithListNavigationViewController:(UIView *)listViewNavigation y:(CGFloat)y height:(CGFloat)height
{
//set x = 0;
NSLayoutConstraint *constraintToAnimate1 = [NSLayoutConstraint constraintWithItem:listViewNavigation
attribute:NSLayoutAttributeLeft
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeLeft
multiplier:0.00
constant:0];
[self.view addConstraint:constraintToAnimate1];
//set y = y;
NSLayoutConstraint *constraintToAnimate2 = [NSLayoutConstraint constraintWithItem:listViewNavigation
attribute:NSLayoutAttributeTop
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeBottom
multiplier:0.00
constant:y];
[self.view addConstraint:constraintToAnimate2];
//set Width = self.view.frame.size.width*0.4
NSLayoutConstraint *constraintToAnimate3 = [NSLayoutConstraint constraintWithItem:listViewNavigation
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:self.view
attribute:NSLayoutAttributeWidth
multiplier:WIDTH_ListTableView
constant:0.0];
[self.view addConstraint:constraintToAnimate3];
//Set height = height
NSLayoutConstraint *constraintToAnimate4 = [NSLayoutConstraint constraintWithItem:listViewNavigation
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:0.00
constant:height];
[self.view addConstraint:constraintToAnimate4];
}
答案 0 :(得分:0)
这是因为您启用了自动布局。尝试使用函数[readViewController.view setTranslatesAutoresizingMaskIntoConstraints:YES]更改框架后更新约束