sammcewan / WYPopoverController

WYPopoverController is for the presentation of content in popover on iPhone / iPad devices. Very customizable.
Other
252 stars 74 forks source link

Misalignment when rapidly changing orientation back and forth #53

Open lozhuf opened 9 years ago

lozhuf commented 9 years ago

If you quickly change the orientation of a device to landscape and then quickly back to portrait, the second orientation change will not trigger the delegate method -popoverController:willRepositionPopoverToRect:inView:

This is because the order in which the notifications didChangeStatusBarOrientation: and didChangeDeviceOrientation are not the same the second time (statusBar notification comes after device), and the _isInterfaceOrientationChanging ivar is not set to YES when the deviceOrientation notification occurs.

This is only visible if you run the code on an actual device - the simulator doesn't allow for such rapid orientation changes. And my testing has so far been limited to iOS 8.

A (quick) fix for this is to remove the use of the ivar flag - the purpose of which is undocumented. What side-effects could we see by removing these lines? (Removing the ivar doesnt fix the issue)

Upon further investigation it seems the didChangeDeviceOrientation is happening 1 run loop earlier than the status change, and at that point even calling the delegate will not solve the problem as all other orientation & layout info hasnt changed yet. The solution I am working on now is implementing a setNeedsReposition method, and calling that in both status & device orientation change methods:

    [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(performReposition) object:nil];
    [self performSelector:@selector(performReposition) withObject:nil afterDelay:0];

Does this seem like a viable solution?