我试图解决的问题:
我在第 5 章中使用了第 05 章示例 06 BookController(C05/06-Scrubbing Pages in 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
不会在开始时出现,但如果你旋转它又开始工作。