[英]How do I shift two UIViews 270px to the right in AutoLayout in code?
我有一个UIView,它在屏幕外向左400像素,宽280像素。
我正在尝试将主UIView移至右侧的280像素,并使屏幕外的UIView像边栏一样在屏幕上同时向右移动。
我被困在这里。
有没有办法在代码中使用NSLayoutConstraints?
编辑:
-(void) setUpSidebar{
self.sidebarViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"SidebarVC"];
self.sidebarViewController.view.frame = CGRectMake(-400, 0, 280, self.sidebarViewController.view.bounds.size.height);
[self.navigationController addChildViewController:self.sidebarViewController];
[self.navigationController.view addSubview:self.sidebarViewController.view];
[self.view insertSubview:self.sidebarViewController.view aboveSubview:self.view];
}
-(void)slideToTheRight{
[UIView animateWithDuration:0.5 animations:^{
self.sidebarOpened = YES;
//self.sidebarViewController.view.frame = CGRectMake(-280, 0, 280, self.sidebarViewController.view.bounds.size.height);
self.view.frame = CGRectMake(280, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}];
[UIView animateWithDuration:0.1 animations:^{
self.sidebarViewController.view.transform = CGAffineTransformMakeTranslation(120, 0);
}];
}
-(void) slideBack{
[UIView animateWithDuration:0.3 animations:^{
self.sidebarOpened = NO;
//self.sidebarViewController.view.frame = CGRectMake(-280, 0, 280, self.sidebarViewController.view.bounds.size.height);
self.view.frame = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
}];
[UIView animateWithDuration:0.2 animations:^{
self.sidebarViewController.view.transform = CGAffineTransformMakeTranslation(-120, 0);
}];
}
当然可以。 使IBOutlet成为要更改的约束,然后在代码中修改其常量参数。 因此,如果在约束的出口处有一个称为leftCon的超级视图的左边缘,则可以这样做:
self.leftCon.constant += 200;
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.