I have a scrollview with pagination. In viewDidLoad i check if the current orientation is landscape then i set its contentsize\'s height 440
if (UIDeviceOri
Here it is a problem in your code. Why you are setting the frame size like this?? You have only the screen size of 320px width
. And when it changes to landscape
, height will be only 320px
. But you are setting the scroll height
as 480px
and it goes out of the screen
and start to scroll diagonally
.
self.scroll.frame = CGRectMake(0,0,480,480);
Instead of that frame size, change like this
self.scroll.frame = CGRectMake(0,0,480,320);
And you need to set the content size depend on the content you are having inside the scroll view in either orientation.
Don't use UIDeviceOrientation
. Use UIInterfaceOrientation
instead. DeviceOrientation
has two extra options you don't need here. (UIDeviceOrientationFaceUp
and UIDeviceOrientationFaceDown
)
Return Yes
from shouldAutorotateToInterfaceOrientation
Now willRotateToInterfaceOrientation: duration:
will be called every time you rotate your device.
Implement this method like this.
-(void)willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
CGRect frame;
int pageNumber = 2;
int statusBarHeight = 20;
if ((toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) || (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight)) {
frame = CGRectMake(0, 0, 480, 320 - statusBarHeight);
} else {
frame = CGRectMake(0, 0, 320, 480 - statusBarHeight);
}
scrollView.frame = frame;
scrollView.contentSize = CGSizeMake(frame.size.width * 2, frame.size.height);
}
Let,
pageNumber = 2
statusBarHeight = 20