我正在开发一个基于 UIPageViewController 的应用程序,它可以在 iPhone 和 iPad 上运行。使用 iPhone 没有问题,因为控制器的脊椎位置始终设置为 UIPageViewControllerSpineLocationMin。然而,在 iPad 中,当设备方向设置为横向时,我需要将脊椎位置设置为 UIPageViewControllerSpineLocationMid。
只有当我以横向加载控制器时,我才会遇到一个奇怪的问题,下面的视频将解释这种情况.. YouTubeVideo
如您所见,当我以纵向加载控制器时,以及在横向加载时旋转设备后,一切正常。
我实在想不通问题出在哪里。这是我用来加载控制器的代码:
if (chapter.controllers) {
currentPage = [chapter bookPageForCharIndex:location];
//Load the correct controller for the bookmark page
NSArray *array = nil;
if (currentPage >= 0 && currentPage < chapter.controllers.count) {
if (UIDeviceOrientationIsLandscape([[UIDevice currentDevice]orientation]) && UI_USER_INTERFACE_IDIOM()==UIUserInterfaceIdiomPad) {
[self setDoubleSided:YES];
if (chapter.controllers.count > currentPage+1) {
array = [[NSArray alloc]initWithObjects:[chapter.controllers objectAtIndex:currentPage],[chapter.controllers objectAtIndex:currentPage+1],nil];
}
else {
array = [[NSArray alloc]initWithObjects:[chapter.controllers objectAtIndex:currentPage],[[[LSBookPageViewController alloc]init]autorelease],nil];
}
}
else {
array = [[NSArray alloc]initWithObjects:[chapter.controllers objectAtIndex:currentPage],nil];
}
}
else {
return;
}
[self playSoundsOfChapter:chapter];
if (isRestarting) {
[self setViewControllers:array
direction:UIPageViewControllerNavigationDirectionReverse
animated:YES
completion:nil];
isRestarting = NO;
}
else {
[self setViewControllers:array
direction:UIPageViewControllerNavigationDirectionForward
animated:YES
completion:nil];
}
[array release];
}