Search code examples
xcodeuiscrollviewsizeboundscgrect

UIScrollView bounds won't change


I have a subclass of a UIScrollView called pagingView. I want to animate it so that when the device is rotated (it is only specific for this viewController and hence landscape mode is turned off in the plist).

I have changed all the clipsToBounds properties and the contentResize properties and autoresizing mask but none seem to work. The code I am using is as follows:

UIDeviceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft)
{

[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.5];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];  
 graph.frame = CGRectMake(pagingView.frame.origin.x, pagingView.frame.origin.y-200, pagingView.frame.size.width*1.5, pagingView.frame.size.height*2);
[UIView commitAnimations];

}

I've changed them to blocks, changed all the properties, however, when i run the code, all it does is move the pagingView by 200 pixels up the screen and the bounds don't change (I've also tried altering the bounds property as well). Any help would be greatly appreciated, I am hoping it is just a simple thing i am missing but I have spent hours searching for solution and the closest potential answer I have got is maybe it has something to do with the layer property?

Thanks in advance!


Solution

  • I recently had a similar issue with scrollview bounds not changing after a device rotation. The solution I found in the end is to add constraints to all four sides of the scroll view in the storyboard. I am using autolayout, iOS7, and XCode5 in simulator mode. Without the constraints, the scroll view would retain for example a (320,480) fixed size in iPhone 3.5" simulator. Very frustrating when I was struggling to diagnose.