Reputation: 41
Overview: I have a strange error where buttons on the right side of my portrait view don't work after rotating to landscape and then back to portrait again.
Detail: Here is the scenario that produces the problem. If I start in portrait, all my buttons work. I rotate to landscape (see code below) and all buttons work. I rotate back to portrait and the buttons on the right 1/4 of the screen do no respond. It's like there is a transparent view that is covering those buttons. What is strange is that if part of the button sticks out to the left of that invisible barrier, I can tap on that part of the button but not on the right part that is "under" the "cover". If I were to rotate to landscape at this point, all the buttons in landscape work. When I rotate back to portrait, that invisible "cover" has moved over to the left another 1/4 to cover roughly 1/2 of the screen. If I rotate again to landscape (all buttons always work in landscape) and then back to portrait, the invisible "cover" has moved over another 1/4 to cover 3/4 of the screen. Eventually, none of my controls respond in portrait.
Important project information:
Here is the code for rotating the views:
[portrait removeFromSuperview];
[landscape removeFromSuperview];
UIDeviceOrientation currentOrientation = [[UIDevice currentDevice] orientation];
if (currentOrientation==UIDeviceOrientationUnknown) {
currentOrientation = (UIDeviceOrientation)[[UIApplication sharedApplication] statusBarOrientation];
}
if ((currentOrientation == 0) || (UIInterfaceOrientationIsPortrait(currentOrientation))) {
[[self view] addSubview:portrait];
}
else { //landscape
[[self view] addSubview:landscape];
}
What I've tried:
Thanks for your help.
Upvotes: 4
Views: 2759
Reputation: 6729
On your Simulator's menu bar select
Debug - > Color Blended Layers
Then Command
+ →
rotate it
Then Command
+ ←
rotate it back
There will probably be a view that gets redimensioned weirdly and covers- maybe partially - your button
Upvotes: 2
Reputation: 1501
i think u r not setting the frame for potrait and landscape properly that means when u rotate it the frame of some other component overlaps with the button frame and so the user interaction gets disabled
Upvotes: 0