如何在 ios objective c 中添加右侧菜单?
how to add right side menu in ios objective c?
我想在我的项目右侧添加侧边菜单。我在我的项目中使用 SWRevealViewController 第三方 类,因为 revealToggle 方法对左侧菜单工作正常,但要在右侧添加菜单,我使用了 rightRevealToggle 方法,但效果不佳。任何建议都会帮助我完成任务。
如果您想在 Objective C 中使用右侧菜单,请使用 MFSideMenu
在您的 AppDelegate 中:
#import "MFSideMenu.h"
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
打开和关闭菜单
// toggle the right side menu
[self.menuContainerViewController toggleRightSideMenuCompletion:^{}];
// close the side menu
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed completion:^{}];
// open the right side menu
[self.menuContainerViewController setMenuState:MFSideMenuStateRightMenuOpen completion:^{}];
如果你想使用SWRevealViewController那么可以使用下面的代码。
设置右视图控制器:
@property (strong, nonatomic) UIViewController *rightViewController;
Animated setting of the front view controller:
- (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated;
Animating the position of the front view controller. Position can be: FrontViewPositionLeftSideMostRemoved, FrontViewPositionLeftSideMost, FrontViewPositionLeftSide, FrontViewPositionLeft, FrontViewPositionRight, FrontViewPositionRightMost or FrontViewPositionRightMostRemoved
- (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated;
Creating and obtaining a pan gesture recognizer:
- (UIPanGestureRecognizer*)panGestureRecognizer;
Creating and obtaining a tap gesture recognizer:
- (UITapGestureRecognizer*)tapGestureRecognizer;
Other methods are documented in the SWRevealViewController.h header file.
您正在使用 SWRevealViewController,如果您想在右侧实现菜单,您只需更改传递给 revealController 的 ViewControllers
来自 SWRevealViewController 的示例
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
revealController.rightViewController = YourViewController;
Please look into AppDelegate.m of RevealControllerProject in the demo
project of SWRevealViewController.
我想在我的项目右侧添加侧边菜单。我在我的项目中使用 SWRevealViewController 第三方 类,因为 revealToggle 方法对左侧菜单工作正常,但要在右侧添加菜单,我使用了 rightRevealToggle 方法,但效果不佳。任何建议都会帮助我完成任务。
如果您想在 Objective C 中使用右侧菜单,请使用 MFSideMenu
在您的 AppDelegate 中:
#import "MFSideMenu.h"
MFSideMenuContainerViewController *container = [MFSideMenuContainerViewController
containerWithCenterViewController:centerViewController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
self.window.rootViewController = container;
[self.window makeKeyAndVisible];
打开和关闭菜单
// toggle the right side menu
[self.menuContainerViewController toggleRightSideMenuCompletion:^{}];
// close the side menu
[self.menuContainerViewController setMenuState:MFSideMenuStateClosed completion:^{}];
// open the right side menu
[self.menuContainerViewController setMenuState:MFSideMenuStateRightMenuOpen completion:^{}];
如果你想使用SWRevealViewController那么可以使用下面的代码。
设置右视图控制器:
@property (strong, nonatomic) UIViewController *rightViewController;
Animated setting of the front view controller:
- (void)pushFrontViewController:(UIViewController *)frontViewController animated:(BOOL)animated;
Animating the position of the front view controller. Position can be: FrontViewPositionLeftSideMostRemoved, FrontViewPositionLeftSideMost, FrontViewPositionLeftSide, FrontViewPositionLeft, FrontViewPositionRight, FrontViewPositionRightMost or FrontViewPositionRightMostRemoved
- (void)setFrontViewPosition:(FrontViewPosition)frontViewPosition animated:(BOOL)animated;
Creating and obtaining a pan gesture recognizer:
- (UIPanGestureRecognizer*)panGestureRecognizer;
Creating and obtaining a tap gesture recognizer:
- (UITapGestureRecognizer*)tapGestureRecognizer;
Other methods are documented in the SWRevealViewController.h header file.
您正在使用 SWRevealViewController,如果您想在右侧实现菜单,您只需更改传递给 revealController 的 ViewControllers
来自 SWRevealViewController 的示例
SWRevealViewController *revealController = [[SWRevealViewController alloc] initWithRearViewController:rearNavigationController frontViewController:frontNavigationController];
revealController.delegate = self;
revealController.rightViewController = YourViewController;
Please look into AppDelegate.m of RevealControllerProject in the demo project of SWRevealViewController.