Leland Krum
Leland Krum

Reputation: 41

UIButtons stop working after rotation to landscape and then back to portrait

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:

  1. This app is universal. The problem only happens in iPad portrait mode. The iPhone version never shows this problem in portrait (or landscape) mode.
  2. There are only 3 views: a container view (which is the root), portrait view, and landscape view.
  3. This app is ARC and targets 6.1. I have all the correct methods to handle rotation events.

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:

  1. The questions I found that sound remotely similar mentioned checking for memory leaks using Instruments. I tried the zombies and allocations templates and didn't see anything odd (though this is the first I've used Instruments).
  2. EDIT: All of this is in the simulator, I haven't tested for this problem on a device yet.

Thanks for your help.

Upvotes: 4

Views: 2759

Answers (2)

Lucas
Lucas

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

Kasaname
Kasaname

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

Related Questions