4

In my

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration;

method, I have code to reposition and resize a scrollview as the app rotates with the device. I do it with the following code:

-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{

    [super willRotateToInterfaceOrientation:toInterfaceOrientation duration:0.5f];

    if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight){
         //landscape
    [mT.buttonScroll setFrame:CGRectMake(0, 544, 1024, 160)];

    }else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft){
        //landscape
    [mT.buttonScroll setFrame:CGRectMake(0, 544, 1024, 160)];

    }else if (toInterfaceOrientation == UIInterfaceOrientationPortrait){
       //portrait
    [mT.buttonScroll setFrame:CGRectMake(0, 800, 768, 160)];

    }else if (toInterfaceOrientation == UIInterfaceOrientationPortraitUpsideDown){
      //portrait
    [mT.buttonScroll setFrame:CGRectMake(0, 800, 768, 160)];

    }
}

Everything rotates properly, but once I rotate a second time the scroll view becomes completely untouchable. Cannot scroll it or touch any of the buttons in it. Then if I rotate back to the previous view the touch comes back and so on. Does anyone know why it is doing this?

Rachel Gallen
  • 27,943
  • 21
  • 72
  • 81
Matt
  • 2,920
  • 6
  • 23
  • 33

5 Answers5

4

Changing the Frame is all well and good but when it comes to UIScrollViews its the contentSize that makes all the difference. You need to set the contentSize when changing the orientation. You can do this by adding something like this when changing orientation.

[mT.buttonScroll setContentSize:CGSizeMake(width, height)];

I assume that mT.buttonScroll is some sort of UIScrollView.

What is happening here is you are resetting the size of the content area to basically the size you want. You can amend the width and the height here.

Hope this helps if not drop us a comment and I will try helping.

Popeye
  • 11,839
  • 9
  • 58
  • 91
0

I think you should use shouldAutorotateToInterfaceOrientation and observe your rotation and UI responsiveness.

In my tests, it works fine with the method I mentioned. willRotatetoInterfaceOrientation gets called after its "should" counterpart. Otherwise, it doesn't get called at all.

esh
  • 2,842
  • 5
  • 23
  • 39
0

In addition to Popeye's answer (which is correct;) I found I needed to set the content size all over the place like this to avoid the issue.

-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:animated];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake (0,100)];
}

-(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake (0,100) ];
}

-(void)viewDidLoad
{
[super viewDidLoad];
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake (0,100) ];
}

-(void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation
{
if ([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"Lanscapse");
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake (0,100];
}
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown )
{
NSLog(@"Portrait");
[scroller setScrollEnabled:YES];
[scroller setContentSize:CGSizeMake (0,100) ];
}
}
Jeff
  • 840
  • 10
  • 29
0

I too faced same issue Follow the following steps: 1.Give top, bottom, leading and bottom constraint to scrollview 2.To the wrapper view within scrollview give top, bottom, leading and bottom as well as equal width with the parent view. 3. Very important step: Link all the internal UI elements with leading, trailing, top, bottom and height. Specially for last elemnt remember to add bottom as well as height and trailing too

komall
  • 1
  • 1
-1

Check out the frame of the scrollview.. After rotation the frame of scrollview is crossing the window frame hence the scrollview is not responding to touch.

Also I am assuming that while calculating rect you are taking into account the other views rect if present Like navigationbar, tabbar, statusbar