Problems with transitionWithView and animateWithDuration

I have problems with transitionWithView and animateWithDuration . One of my animateWithDuration blocks animateWithDuration not transition, this is a sudden change, and transitionWithView does not temporarily disable user interaction. I checked the documents and I think that I am doing everything right, but, obviously, something is wrong. Here are two blocks of code:

This is in my main View ViewController controller, which has three kinds of container / child controllers. This block moves one of the container views, but does not block the user from other interactions in the ViewController while the transition is in progress.

 [UIView transitionWithView:self.view duration:0.5 options:UIViewAnimationOptionCurveEaseOut animations:^ { CGRect frame = _containerView.frame; frame.origin.y = self.view.frame.size.height - _containerView.frame.size.height; _containerView.frame = frame; }completion:^(BOOL finished) { // do something }]; 

This is one of my container controllers. The animation does not seem to work because the text productTitleLabel and productDescriptionTextView changes suddenly, as if the animation block did not exist.

 - (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath { [self.viewController toggleFlavoredOliveOilsTableView]; if (indexPath.row > 0) { NSDictionary *selectedCellDict = [[_flavoredOliveOilsDict objectForKey:@"Unflavored Olive Oils"] objectAtIndex:indexPath.row - 1]; [UIView animateWithDuration:0.5 delay:0 options:UIViewAnimationOptionTransitionCrossDissolve animations:^ { self.viewController.productTitleLabel.text = [_flavoredOliveOilsTableView cellForRowAtIndexPath:indexPath].textLabel.text; self.viewController.productDescriptionTextView.text = [selectedCellDict objectForKey:@"Description"]; }completion:nil]; if (indexPath.row == 1) { [self.viewController setProductDescriptionTextViewFrameForInformationTab]; } else { [self.viewController setProductDescriptionTextViewFrameForNonInformationTab]; //self.viewController.productImageView.image = [UIImage imageNamed:[selectedCellDict objectForKey:@"Image"]]; } } } 

I think the problems are somewhat related to the fact that most of my animation and transition blocks do not work fully as expected. Thanks for any help.

Edit

What I'm trying to accomplish is moving the container view into the ViewController and setting the text and image properties of the label, text view and image; all of which are in the main window. Details of these properties are sent through the child view controller. transitionWithView is in the toggleFlavoredOiveOilsTableView method, which is called in didSelectRowAtIndexPath . I think the problem is that I am trying to call two different animation / transition blocks at the same time.

+7
source share
1 answer

You can experience this behavior of two animations interfering with each other if one animation is performed in the view mode of another view that is passing through the animation. That way, if you do transitionWithView:self.view (i.e., in the main view), as your code snippet suggests, you might have problems. If you perform two animations in different subtitles, the problem may disappear. In my original answer below, I:

  • Run transitionWithView in the subtitle that has two UILabel ;

  • Put my controller view views in child views in the subview of the main view, and then the transitionFromViewController will be bound to this view.

When I place two animated parts in different subzones, animations can be performed simultaneously without incident.


If you want to animate the change in the contents of two text labels, you can:

 [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]; 

I usually use animateWithDuration , but the text attribute is not an animating property, so I use transitionWithView , making sure that I have a container for these text fields. But I tried to animate other controls using animateWithDuration while animating the change of child controllers at the same time, and it works great.

To navigate to the child view controllers, I use transitionFromViewController to animate the rearrangement of the views of the child container controller (this is part of Managing child controllers in Custom of Container ). To facilitate this process, I put the container view into the view of the main view controller and add the views of the child controller as a subtask of this container. Thus, when I animate the transition of a child, the animations are perfectly attached to this container view.

So, here is a sample code to add a view controller to my container view, and then the code that I use to navigate between two child view controllers using a segmented button:

 - (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 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]; }]; } 

On the bottom line, I have no problem animating both the child controllers of the container and the fields in the parent controller. Perhaps I do not understand the problem you are describing. Or maybe there is something subtle about the differences in how we animate. If you want, I posted this code on github above if you want to take a look.

+13
source

All Articles