201

2013-01-19

As your app design and development goes on you decide that is good to use a UIPageControl??to navigate though a series of UIView (or UIViewControllers). If you are using iOS 6, Auto Layout is enabled on your storyboard. Later you will discover that this is the point of trouble. If you google around to find a suitable example probably you will find: Using UIPageControl as a container UIViewController from wannabegeek blog a great tutorial that works in iOS 5. In iOS 6, auto layout refuse to work with UIScrollView as it is in this tutorial. If you look around (iOS 6 release notes), you will find that obviously there are some changes. So what I can to do in order to have my UIPageControl working? In PageViewController.m, modify viewWillAppear as follow: [sourcecode language=“objc”] - (void)viewWillAppear:(BOOL)animated { [super viewWillAppear:animated]; // add this in order UIScrollView work with Auto layout if (IS_WIDESCREEN) { self.scrollView.frame = CGRectMake(0, 0, 320, 468); } else { self.scrollView.frame = CGRectMake(0, 0, 320, 380); } … } [/sourcecode] and in the same fashion viewWillDisappear [sourcecode language=“objc”] - (void)viewWillDisappear:(BOOL)animated { …. // add this in order UIScrollView work with Auto layout if (IS_WIDESCREEN) { self.scrollView.contentSize = CGSizeMake(320, 468); } else { self.scrollView.contentSize = CGSizeMake(320, 380); } } [/sourcecode] Credits to Mr KadoreIS_WIDESCREEN is the following macro [sourcecode language=“objc”] #define IS_WIDESCREEN ( fabs( ( double )[ [ UIScreen mainScreen ] bounds ].size.height - ( double )568 ) < DBL_EPSILON ) [/sourcecode] in order to recognise iOS devices with screen height of 568, like iPhone 5.