我试图过渡我们的应用程序,使用SWRevealViewController给我们一个侧栏在应用程序的每一侧。但是,尽管在其中一个示例应用程序中使用了代码,但是前端视图的ViewController无法正常工作时出现错误。 viewDidLoad被调用,但一切都保持黑色。SWRevealViewController FrontViewController不加载,卡住为黑色,其他视图很好
有趣的是,如果在我的viewDidLoad中,我将背景颜色设置为视图的红色,这就反映出来了。但从原始故事板的界面生成器中的东西不是。
我在AppDelegate中使用的代码是:
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
self.window = window;
MainViewController *frontViewController = [[MainViewController alloc] init];
RearViewController *rearViewController = [[RearViewController alloc] init];
UINavigationController *frontNavigationController = [[UINavigationController alloc] initWithRootViewController:frontViewController];
UINavigationController *rearNavigationController = [[UINavigationController alloc] initWithRootViewController:rearViewController];
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
RightViewController *rightViewController = rightViewController = [[RightViewController alloc] init];
rightViewController.view.backgroundColor = [UIColor greenColor];
revealController.rightViewController = rightViewController;
//revealController.bounceBackOnOverdraw=NO;
//revealController.stableDragOnOverdraw=YES;
self.viewController = revealController;
self.window.rootViewController = self.viewController;
[self.window makeKeyAndVisible];
return YES;
}
#pragma mark - SWRevealViewDelegate
- (id <UIViewControllerAnimatedTransitioning>)revealController:(SWRevealViewController *)revealController animationControllerForOperation:(SWRevealControllerOperation)operation fromViewController:(UIViewController *)fromVC toViewController:(UIViewController *)toVC
{
if (operation != SWRevealControllerOperationReplaceRightController)
return nil;
if ([toVC isKindOfClass:[RightViewController class]])
{
if ([(RightViewController*)toVC wantsCustomAnimation])
{
id<UIViewControllerAnimatedTransitioning> animationController = [[CustomAnimationController alloc] init];
return animationController;
}
}
return nil;
}
这是Main.Storyboard这仅仅是为MainViewController:
当应用程序加载时,该视图仅仅是黑色的。但是我可以从左右两边拖动,并按照预期的方式查看侧栏。所以只有FrontView才会变黑。我将一个NSLog()插入到ViewDidLoad中,它出现在控制台中,就像 - (void)loadView {}中的一样,它显示View正在加载。
如果我把viewDidLoad一个[self.view setBackgroundColor:[UIColor redColor]]
这个生效,这意味着它链接到视图,但它只是故事板内的视图没有出现。这是奇怪的,因为故事板还包含一个NavigationController,它确实出现了(我认为 - 除非导航控制器来自其他地方 - 我敢肯定它不是)。
有关可能会导致此问题的任何想法?
谢谢......它的工作原理 – Roger 2016-06-13 12:23:04