Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>You can experience this behavior of two animations interfering with each other if one animation is done on subview of another view undergoing animation. Thus, if you perform <code>transitionWithView:self.view</code> (i.e. on the main view) like your code snippet suggests, you can have problems. If you perform the two animations on distinct subviews, the problem may go away. In my original answer below, I:</p> <ul> <li><p>Perform <code>transitionWithView</code> on a subview that has the two <code>UILabel</code> controls;</p></li> <li><p>Put my view controller containment child views within a subview of the main view, and then the <code>transitionFromViewController</code> is constrained to that subview. </p></li> </ul> <p>When I put the two animated portions on distinct subviews, the animations can take place simultaneously without incident.</p> <hr> <p>If you want to animate the changing of the contents of two text labels, you can:</p> <pre><code>[UIView transitionWithView:self.viewController.textLabelsContainerView duration:0.5 options:UIViewAnimationOptionTransitionCrossDissolve animations:^{ self.viewController.productTitleLabel.text = [_flavoredOliveOilsTableView cellForRowAtIndexPath:indexPath].textLabel.text; self.viewController.productDescriptionTextView.text = [selectedCellDict objectForKey:@"Description"]; } completion:nil]; </code></pre> <p>Generally I'd use <code>animateWithDuration</code>, but the text attribute is not an animatable property, so that's why I use <code>transitionWithView</code>, making sure that I have a container for those text fields. But I've tried animating other controls using <code>animateWithDuration</code>, while simultaneously animating the changing of the child controllers, and it works fine.</p> <p>For transitioning the child view controllers, I use <code>transitionFromViewController</code> to animate the swapping of the containers child controller's views (it's part of the <a href="http://developer.apple.com/library/ios/documentation/uikit/reference/UIViewController_Class/Reference/Reference.html#//apple_ref/doc/uid/TP40006926-CH3-SW86" rel="noreferrer">Managing Child View Controllers in a Custom Container</a> family of methods). In order to facilitate that process, I put a container view on my main view controller's view, and add the child controller's views as a subview of that container. That way, when I animate the transition of the child, the animations are nicely constrained to that container view.</p> <p>So, here is some sample code to add a view controller to my container view, and then the code I use to transition between two child view controllers using a segmented button:</p> <pre><code>- (void)addFirstChild { UIViewController *child = [self.storyboard instantiateViewControllerWithIdentifier:@"Stooge"]; [self addChildViewController:child]; child.view.frame = self.bottomContainerView.bounds; [self.bottomContainerView addSubview:child.view]; [child didMoveToParentViewController:self]; } - (void)changedChild { UIViewController *oldController = [self.childViewControllers lastObject]; UIViewController *newController; if (self.segmentedControl.selectedSegmentIndex == 0) newController = [self.storyboard instantiateViewControllerWithIdentifier:@"Stooge"]; else newController = [self.storyboard instantiateViewControllerWithIdentifier:@"Marx"]; [oldController willMoveToParentViewController:nil]; [self addChildViewController:newController]; // start off screen below CGRect startFrame = self.bottomContainerView.bounds; startFrame.origin.y += startFrame.size.height; // end up where it's supposed to be, right in the container newController.view.frame = startFrame; [self transitionFromViewController:oldController toViewController:newController duration:0.5 options:0 animations:^{ newController.view.frame = self.bottomContainerView.bounds; } completion:^(BOOL finished) { [oldController removeFromParentViewController]; [newController didMoveToParentViewController:self]; }]; } </code></pre> <p>Bottom line, I have no problem animating both container child controllers and the fields in the parent controller. Perhaps I'm not understanding the problem you're describing. Or maybe there's something subtle about the differences in how we're animating. If you want, I've put <a href="https://github.com/robertmryan/containment-animation" rel="noreferrer">this above code</a> on github if you want to take a look.</p>
 

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