Flicker during iOS 7 controller custom transition

I'm trying to make a very simple transition: one view moves half the screen to the left, and the second ("to") view moves half the screen.

My animation works, but when I change the animation, I see a flicker. The "to" view (i.e., the Original view) is displayed at the beginning of 0.0, although I am setting a different frame.

I dropped the view hierarchy. The frames are set correctly (-100 0; 320 480 for viewing), but nevertheless it is displayed at 0.0. Is a screenshot of a view cached somewhere for animation?

- (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext { UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; UIView *container = [transitionContext containerView]; CGRect offsetCoverRect = CGRectMake(-100.0, 0.0, 320, 480); CGRect detailsRect = CGRectMake(-100.0 + 320.0, 0.0, 320, 480); CGRect detailsOutsideRect = CGRectMake(320.0, 0.0, 320, 480); CGRect normalRect = CGRectMake(0.0, 0.0, 320, 480); if (self.revealDetails) { toViewController.view.frame = detailsOutsideRect; [container addSubview:toViewController.view]; } else { [container insertSubview:toViewController.view belowSubview:fromViewController.view]; // reversing… set the frame to the original offset (shows at 0,0 for a moment) toViewController.view.frame = offsetCoverRect; } [UIView animateKeyframesWithDuration:2 delay:0 options:0 animations:^{ if (self.revealDetails) { fromViewController.view.frame = offsetCoverRect; toViewController.view.frame = detailsRect; } else { fromViewController.view.frame = detailsOutsideRect; toViewController.view.frame = normalRect; } } completion:^(BOOL finished) { [transitionContext completeTransition:finished]; }]; } 

Update:

This seems to be related to the UIModalPresentationCustom . I need to use this so that it is not removed from the view when the transition is completed. However, it seems that it is assumed that the view controller for the inverse transition starts at 0.0.

Update 2:

It is very easy to reproduce the following code:

 UIView *snapshot = [containerView snapshotViewAfterScreenUpdates:NO]; [containerView addSubview:snapshot]; 

The above will be displayed on the screen in the center, regardless of what actual frame or center I set before the animation.

+7
ios objective-c uiviewcontroller ios7 uiviewanimation
source share
2 answers

I know this is an old question, but I ran into the same problem and after several hours of struggle, finally came up with a solution:

In the current animation completion block

  • Creating a snapshot of a view fromViewController
  • Execute frame of change / conversion on the snapshot
  • Add snapshot to containerView
  • Remove fromViewController view from container view
  • In the block for terminating the dismissal animation (or anywhere, if he is dismissed?), Remove the picture from the container

Retrieving the fromViewController view from the container view, it does not get reset to its original position, because it is no longer inside the container view.

+2
source share

This is because your animateTransition method is being called from the background. Call your method this way

 dispatch_async(dispatch_get_main_queue(), ^ { [self animateTransition]; // your method goes here }); 

You should never call animations or any UI-related methods in the background thread.

-2
source share

All Articles