1

私が解決しようとしている問題:

UInavigatioControllerをrootViewControllerとして持つプロジェクトで、第5章(C05 / 06- https://github.com/erica/iOS-5-Cookbook.gitのページをスクラブ)で第05章の例06 BookControllerを使用しましたが、使用していませんランドスケープモードで正しく起動します。デバイスを縦向きに回転させて横向きに戻すと、デバイスが機能し始めます。

バグを表示するには、main.cのテストベッドデリゲートの例を次のように変更します。

#pragma mark Application Setup
@interface TestBedAppDelegate : NSObject <UIApplicationDelegate>
{
    UIWindow *window;
}
@end
@implementation TestBedAppDelegate

TestBedViewController *tbvc;
UINavigationController *navigationController;

- (void) pushBookController: (UIGestureRecognizer *) recognizer
{
    [navigationController pushViewController:tbvc animated:YES];
}

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions 
{   
    window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
    tbvc = [[TestBedViewController alloc] init];

    UIViewController *start = [tbvc controllerWithColor:[UIColor whiteColor] withName:@"white"];
    UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(pushBookController:)];
    [start.view addGestureRecognizer:tap];

    navigationController = [[UINavigationController alloc] initWithRootViewController:start];

    window.rootViewController = navigationController;
    [window makeKeyAndVisible];
    return YES;
}
@end

私のアプリケーションは横向きで起動するので、問題はブックコントローラーが起動時に横向きモードを認識しないことです(起動後に回転すると機能します)。それを試してみてください。

開始時にランドスケープを認識するには、BookControllerで次のメソッドに置き換えます

// Entry point for external move request
- (void) moveToPage: (uint) requestedPage
{
    //[self fetchControllersForPage:requestedPage orientation:(UIInterfaceOrientation)[UIDevice currentDevice].orientation];
    [self fetchControllersForPage:requestedPage orientation:self.interfaceOrientation];
}

そして、以下を追加します。

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

ここで問題となるのはBookController、最初は表示されないことですが、回転させると機能し始めます。

4

1 に答える 1

1

おそらくあなたはすでにこれを解決しましたが、本のインスタンス化を次のように変更してみてください:

+ (id) bookWithDelegate: (id) theDelegate
{   

    NSDictionary *options = nil;
    //Check the orientation
    if (UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation])) {
        //Setting Spine Location to middle for Landscape orientation
        options =  [NSDictionary dictionaryWithObject:
                    [NSNumber numberWithInteger:UIPageViewControllerSpineLocationMid]
                                           forKey: UIPageViewControllerOptionSpineLocationKey];
    }

    BookController *bc = [[BookController alloc] initWithTransitionStyle:UIPageViewControllerTransitionStylePageCurl navigationOrientation:UIPageViewControllerNavigationOrientationHorizontal options:options];

    bc.dataSource = bc;
    bc.delegate = bc;
    bc.bookDelegate = theDelegate;

    return bc;
}

スパインを設定するためにstatusBarOrientationチェックを追加していることに注意してください。

基本的に必要なのは、UIPageViewControllerを作成するときに方向を確認することであり、私はstatusBarOrientationを使用しました。

ああ、そしてあなたが正しい方向を向いていることを確認することを忘れないでください

- (BOOL) useSideBySide: (UIInterfaceOrientation) orientation
{
    BOOL isLandscape = UIInterfaceOrientationIsLandscape(orientation);
    // in case the UIInterfaceOrientation is 0.
    if (!orientation) {
        isLandscape = UIInterfaceOrientationIsLandscape([[UIApplication sharedApplication] statusBarOrientation]);
    }
    return isLandscape;    
}

ps:bookWithDelegateメソッドは、質問で言及された例内のBookControllerクラスに対応します。

于 2012-02-09T14:46:02.413 に答える