質問

I have a button in one of view controller of tab bar controller. All set up in storyboard. I registered action method like this

- (IBAction)buttonPressed:(id)sender {
    NSLog(@"Button pressed");
}

The thing is that once I make left and top constraints (to force it stay in the right upper corner) touch up inside event stops working after I change rotation. So just open app in portrait mode - method is working. Change to landscape and I cannot tap button suddenly.

I've recreated problem in this easy example project.

Many thanks.

役に立ちましたか?

解決

Just put the following code in you TabBarViewController class.

- (void)viewDidLayoutSubviews
{
    // fix for iOS7 bug in UITabBarController
    self.selectedViewController.view.superview.frame = self.view.bounds;
}

他のヒント

Recently I noticed same bug in my application. First I tried Slavco Petkovski method. But this caused me another bug with rotating and getting right bounds and frame, so I kept searching.

I found another solution for this problem, mainly setting autoresizing mask of view controller's view in xib. But since arrows in inspector in my Xcode (version 5.0.1) are inactive and you can't set them, you have to open xib file in text editor find autoresizingMask property for main view and change it like this:

<autoresizingMask key="autoresizingMask" widthSizable="YES" heightSizable="YES"/>

EDIT:

Alternatively you can do this in your view controller's code - same result as in changes in xcode:

self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top