我一直在使用SWRevealViewController库很长一段时间没有问题,我真的很喜欢它! 这次我不得不将它添加到项目中,所以这就是我所做的:
这就是我的初始化代码:
FrontViewController *frontViewController = [[FrontViewController 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;
self.swViewController = revealController;
self.window.rootViewController = self.swViewController;
[self.window makeKeyAndVisible];
return YES;
当我启动应用程序时,这会因无限循环而崩溃。这是调用堆栈:
...(here comes inifite calls to transitionFromViewController)...
#36603 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36604 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36605 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36606 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36607 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36608 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36609 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36610 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36611 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36612 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36613 0x00118620 in __80-[SWRevealViewController _transitionFromViewController:toViewController:inView:]_block_invoke_2 at /path/to/myproject/SWRevealViewController.m:1683
#36614 0x0011759c in __82-[SWRevealViewController _performTransitionOperation:withViewController:animated:]_block_invoke at /path/to/myproject/SWRevealViewController.m:1470
#36615 0x0011757e in -[SWRevealViewController _performTransitionOperation:withViewController:animated:] at /path/to/myproject/SWRevealViewController.m:1497
#36616 0x001137be in -[SWRevealViewController initWithRearViewController:frontViewController:] at /path/to/myproject/SWRevealViewController.m:635
#36617 0x000e1ec0 in -[AppDelegate application:didFinishLaunchingWithOptions:] at /path/to/myproject/AppDelegate.m:35
我直接测试了样品,当然它有效。 我正在使用Xcode 8,而我正在使用iOS 10.1进行编译。 我正在做的唯一“不同”的事情是我的应用程序只是风景,我不知道这是否会影响侧边菜单。
它会发生什么?
答案 0 :(得分:0)
对于左侧滑动菜单,使用SWRevealViewController
library的代码现在几乎没有变化,为了正确使用,这里有一些棘手的步骤。
班级配置:
在项目及其故事板中添加几个类download link:
SWRevealViewController.h
SWRevealViewController.m
SidebarViewController.h
SidebarViewController.m
要创建前视图和罕见视图,请参阅故事板配置。
要在菜单中添加更多viewControllers
,首先需要创建可可类并添加以下代码。
导入"SWRevealViewController.h"
@property (weak, nonatomic) IBOutlet UIBarButtonItem *sidebarButton;
在.m文件中,在viewDidLoad
方法中添加以下代码:
// Change button color
_sidebarButton.tintColor = [UIColor colorWithWhite:0.1f alpha:0.9f];
// Set the side bar button action. When it's tapped, it'll show up the sidebar.
_sidebarButton.target = self.revealViewController;
_sidebarButton.action = @selector(revealToggle:);
// Set the gesture
[self.view addGestureRecognizer:self.revealViewController.panGestureRecognizer];
Stroyboard配置:
为了制作前视图viewController
要将其他viewController
配置为菜单,您必须使用不带标识符的segue从Sidebar scene
vc's
单元格连接它们。
在点按之前连接所有sidebarButton
IBOutlet
。
要添加更多viewController,您需要在Sidebar scene
vc中添加单元格,并在menuItems
类中的SidebarViewController.m
数组中进行一些更改,但不要忘记创建该单元格识别与menuItmes相同。
menuItems = @[@"title", @"news", @"comments", @"map", @"calendar", @"wishlist", @"bookmark", @"tag", @"anotherVc_1", @"anotherVc_2"];
注意:您可以从prepareForSegue
类中删除SidebarViewController.m
个方法,并为所有转换单元格生成单独的vc,prepareForSegue
方法处理segue传输,这会重定向用户,因此vc与差异外观。
希望这会对你有所帮助。