SCLAlertView-Swift
SCLAlertView-Swift copied to clipboard
Taps on buttons not handled after device rotation
It sometimes happens that if you:
- show alert -> rotate device -> taps on buttons are not handled anymore.
Had the same issue - start with landscape mode and then you go to portrait mode while alert is present the cancel button doesn't work anymore. It seems like the last button does not register. This occurs when you have at least 2 buttons.
👍 Confirmed
I have two buttons in an alert and neither work after rotating. This happens from portrait -> landscape and landscape -> portrait. Rotating back to the original orientation allows the buttons to work again.
If you set clipToBounds on all subviews, you can see that the alert view gets sized improperly. And since taps outside of the view bounds aren't processed, the buttons seem to be ignoring touches.
If you start portrait and rotate landscape, the right side cuts off half way. If you start landscape and rotate portrait, the bottom half is cut off half way. In the first case, you can still see parts of the buttons and those visible parts do, in fact, work when tapped.
I believe the problem is that the library doesn't set the autoresizingMask. If you add this code after showing a view, everything works just fine:
for sv in alertView.view.subviews {
sv.autoresizingMask = [ .flexibleHeight, .flexibleWidth ]
}
There only a single subview, which I'd imagine is the baseView instance variable, but it's inaccessible.