【问题标题】:UIPageViewController black screen on iPad when loaded in landscape横向加载时iPad上的UIPageViewController黑屏
【发布时间】:2012-08-14 09:56:56
【问题描述】:

我正在开发一个基于 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];
    }

【问题讨论】:

    标签: objective-c ipad ios5 landscape uipageviewcontroller


    【解决方案1】:

    我认为错误出现在第一个 else 子句中。您应该在检查设备方向和设备后设置断点,并单步执行代码。我猜你的array 是空的。

    【讨论】:

    • 这里发生了一些奇怪的事情。在那个范围内,数组已满(2个元素),但如果我这样检查:-(void)viewDidAppear:(BOOL)animated{ NSLog(@"% d",[[self viewControllers]count]); } 我得到一个 0...
    • 在这里,当控制器以横向加载时,spineLocation 未设置为“Mid”。即使我调用 [self pageViewController:pageViewController spinLocationForInterfaceOrientation:[[UIDevice currentDevice]orientation]] 脊椎位置设置不正确(方法已执行)...
    • @Lolloz89 我只想说检查 [self viewControllers] 非常有用,感谢您的建议,因为它帮助我找到了我的问题。
    猜你喜欢
    • 2023-04-04
    • 2012-01-15
    • 2012-10-29
    • 1970-01-01
    • 2012-12-14
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-12-10
    相关资源
    最近更新 更多