2011-12-04 9 views
1

私が解決しようとしている問題:BookController風景モードでは正常に起動しない

私は(C05/06-スクラブページの第5章の章05例06 BookControllerを使用in https://github.com/erica/iOS-5-Cookbook.git)、UInavigatioControllerをrootViewControllerとして持つプロジェクトでは、横向きモードで正しく起動しません。デバイスのポートレートを回転させて風景に戻すと、作業が始まります。

#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 

(私のアプリケーションは、風景を開始し、その問題は本コントローラは起動時にランドスケープモードを認識しないということである:バグは以下にmain.cの例のテストベッドのデリゲートを変更表示するには

あなたが起動した後に回転するなら、それはうまくいくでしょう)。それを試してみてください。以下の方法

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

、開始時にBookControllerで代用風景を認識し、以下を追加するには

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

さて問題はBookControllerは、開始時に表示されますが、再び場合はいないということですそれを回転させると作業が始まります。

答えて

1

おそらくあなたはすでにこれを解決しますが、このようにブックのインスタンス化を変更してみてください:私は背骨を設定するにはstatusBarOrientationチェックを追加している

+ (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; 
} 

注意。

基本的には、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クラスに対応しています。

関連する問題