views:

1067

answers:

2

My app design requires the same scrolling functionality found in the iPhone's native Photos app when browsing photos in full screen. Specifically:

  • Each view snaps into place as the view is swiped
  • Scrolling happens in only one direction
  • Rotating the iPhone rotates the entire scrolling region as well such that the frame of each subview (photos, in Apple's case) rotates in-place and paging is still in the same direction (left-to-right)

I started to use Apple's sample PageControl code as a launching point, and everything was going swimmingly until I attempted adding autorotation to the code. My sense from the docs was that all I had to do to get autorotation working was to add this to the sample code's MyViewController.m

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
 return YES;
}

While that does seem to cause the subviews' backgrounds to rotate, the UILabels and the enclosing UIScrollView stay fixed so that, from a user perspective, paging through the views now requires up/down flicking instead of left/right.

A: 

For starters, you need to go fiddle with the autoresizing masks on the page control and scrollview (in that sample). I'm still exploring the sample to see what else is required. May have more info in a bit, if someone else doesn't provide the definitive solution before then...

wkw
Thanks for the feedback, wkw. I'm looking into using setAutoresizingMask and setAutoresizesSubviews, but so far haven't produced any change. I'm thinking that I need a much clearer understanding of the view hierarchy in this project. I'll take a closer look.
clozach
A: 

On a whim, I read the stackoverflow post titled "UIButtons don’t respond to touch after set frame on autorotate". It links to the blog post below which includes working code that handles all the complex transforms that Apple's sample doesn't include.

Props to Björn Sållarp for making this solution freely available!

http://blog.sallarp.com/shouldautorotatetointerfaceorientation/

clozach