imObjCSwifting
imObjCSwifting

Reputation: 743

UIButtons in UIScrollView is not touchable after rotate to landscape orientation using Storyboard and Autolayout?

I have a lot of "Buttons" in a View in a ScrollView, in a SuperView, of the ViewController.

ViewController
   View
      ScrollView
         View
            Button
            Button
            Button
            Button
            Button
            ....

I use autolayout, View to ScrollView (trailing, top, bot, lead 0, align x,y center) same for ScrollView to ViewController.View.

when rotate to landscape mode, the screen only recognizes touches from x 0 to 320, any button after x 320 is not touchable.

I did change the frame of the SuperView, ScrollView and Content View but did not do anything

-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
    if (UIInterfaceOrientationIsLandscape(toInterfaceOrientation)) {
        _contentView.frame = CGRectMake(0, 0, 1000,1000);
        _mainView.frame = CGRectMake(0, 0, 1000,1000);
        _scrollView.frame = CGRectMake(0, 0, 1000,1000);

        NSLog(@"size of self is %@",NSStringFromCGSize(self.view.frame.size));
        NSLog(@"size of scrollview is %@",NSStringFromCGSize(_scrollView.frame.size));
        NSLog(@"size of contentView is %@",NSStringFromCGSize(_contentView.frame.size));
        NSLog(@"size of MainView is %@",NSStringFromCGSize(_mainView.frame.size));

    } else {
    }
}

Does anyone know why?

Thanks.

As Matt suggested, I change the frame after the rotation (didRotateFromInterfaceOrientation). Here are the log of the frames of the views and one button not touchable

2014-04-29 18:08:27.528 [84526:60b] size of self is {{0, 0}, {568, 288}}
2014-04-29 18:08:27.529 [84526:60b] size of scroolview is {{0, 0}, {568, 336}}
2014-04-29 18:08:27.529 [84526:60b] size of content is {568, 466}
2014-04-29 18:08:27.529 [84526:60b] size of contentView is {{0, 0}, {568, 466}}
2014-04-29 18:08:27.530 [84526:60b] size of MainView is {{0, 0}, {568, 288}}
2014-04-29 18:08:27.530 [84526:60b] size of myBtn is {{364, 45}, {50, 50}}

So myBtn is inside the contentView yet it's not touchable?

Upvotes: 1

Views: 336

Answers (1)

MiQUEL
MiQUEL

Reputation: 3001

Do you get any constraint warning when you rotate the device?

I had the same issue, was able to see a pickerview but were not tappable when I rotate the device. after return to the previous orientation worked again.

In my case the solution was to remove all constraints (backup project first) and reset to suggested constraints.

Then It worked.

Hope it helps.

As interesting info: I'll tell you this started to happen, after I update XCode from 4.X to 5.0, so, probably something in the storyboard was not upgraded correctly.

Upvotes: 1

Related Questions