3

I have viewController1 (in a UINavigationController)that presents viewController2 The problem is that while the viewController2 is being presented (takes about 0.2s), an event in the app can cause viewController1 to be popped.

Then I get:

unbalanced calls to begin/end appearance transitions for DetailsViewController: 0x7e6191a0.

and also viewController2 is left “orphaned” on the screen (there is no way to remove it)..

Here is code (in Xamarin c# but it the same problem in Objective C):

this.PresentViewController(viewController2, animated: true, completionHandler: null); // takes 0.2s to animate
//
// then 0.1s later, say, this is called:
//
this.DismissViewController(animated: false, completionHandler: null);
this.NavigationController.PopToRootViewController(animated: false);

The problem is that this.DismissViewController does not actually dismiss viewController2 while it is still animating.

(A similar problem occurs if a Push animation is in progress).

A solution is “queue” the request for PopToRootViewController and run it in the completionHandler for this.PresentViewController. But this is very cumbersome and means all events in the app have to be queued and all animations have to have completionHandler’s.

I really need a way to cancel the present animation (this.View.Layer.RemoveAllAnimations() doesn’t work for presentViewController) so that DismissViewController will then work and PopToRootViewController can be called without problems.

How do people deal with this "uncancellable animation" problem?

UPDATE:

Also there is a related problem now we have to use UIAlertController instead of UIAlert, see for background:

Show UIAlertController if already showing an Alert

We have to wait for any presentViewController animation to complete before presenting a UIAlertController. This is hard for things like a Push Notification which we want to show in an alert but it may arrive during an animation.

Community
  • 1
  • 1
Bbx
  • 3,184
  • 3
  • 22
  • 33
  • This doesn't sound like a good UI to me. The user does something to cause a controller to be presented, but then that gets cancelled in mid presentation? I think this would be confusing to the user. What event is so important that you can't wait until the new controller is presented (and maybe present an alert to let the user know what's happening)? – rdelmar Nov 22 '14 at 16:09
  • Well its when things are updated in background. Eg the Mail app on iPhone, you may be viewing a message, then the email is deleted on another client and it updates the mail app to remove the message. It would be horrible to put up an alert in that situation. – Bbx Nov 22 '14 at 16:27
  • See also the UPDATE above about having to wait before using UIAlertController – Bbx Nov 22 '14 at 16:40

0 Answers0