iOS 5開発者のクックブック(Erica Sadun)のBookControllerは、ランドスケープモードでは正しく開始されません

StackOverflow https://stackoverflow.com/questions/8374226

質問

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

第5章の例06 bookcontrollerを使用しました。 https://github.com/erica/ios-5-cookbook.git )uinavigatiocontrollerをrootviewcontrollerとして持っているプロジェクトでは、ランドスケープモードでは正しく開始されません。デバイスのポートレートを回転させて風景に戻ると、動作し始めます。

バグを表示するには、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 開始時には表示されませんが、回転すると機能し始めます。

役に立ちましたか?

解決

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

+ (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を作成するときにオリエンテーションを確認することです。SatupsBarorientationを使用しました。

ああ、そしてあなたが正しいオリエンテーションを得ることを確実にすることを忘れないでください

- (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クラスに対応しています。

ライセンス: CC-BY-SA帰属
所属していません StackOverflow
scroll top