Note that there are some explanatory texts on larger screens.

plurals
  1. POHow do I shift two UIViews 270px to the right in AutoLayout in code?
    text
    copied!<p>I have a UIView that is offscreen 400 pixels to the left and is 280 pixels wide.</p> <p>I'm trying to shift the main UIView to the right 280 pixels and to have the offscreen UIView move onscreen to the right simultaneously like a sidebar.</p> <p>I've been stuck here.</p> <p>Is there a way to do this in code and to use NSLayoutConstraints?</p> <p>Edit:</p> <pre><code>-(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); }]; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload