受照 Dribbble 射击的 iOS 7/8 风格侧边菜单,具有视差效果(第一个和 第二个)。
从版本 4.0 开始,您可以在内容视图控制器左右两侧添加菜单视图控制器。
在 xcode 中构建并运行 RESideMenuExample
项目,以查看 RESideMenu 的实际效果。对于故事板集成演示,构建并运行 RESideMenuStoryboardsExample
。
您需要做的就是将 RESideMenu
文件拖放到您的项目中,并于要使用它的类顶部添加 #include "RESideMenu.h"
。
在您的 AppDelegate 的 - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
中创建视图控制器,并将内容视图控制器和菜单视图控制器分配给它。
// Create content and menu controllers
//
DEMONavigationController *navigationController = [[DEMONavigationController alloc] initWithRootViewController:[[DEMOHomeViewController alloc] init]];
DEMOLeftMenuViewController *leftMenuViewController = [[DEMOLeftMenuViewController alloc] init];
DEMORightMenuViewController *rightMenuViewController = [[DEMORightMenuViewController alloc] init];
// Create side menu controller
//
RESideMenu *sideMenuViewController = [[RESideMenu alloc] initWithContentViewController:navigationController
leftMenuViewController:leftMenuViewController
rightMenuViewController:rightMenuViewController];
sideMenuViewController.backgroundImage = [UIImage imageNamed:@"Stars"];
// Make it a root controller
//
self.window.rootViewController = sideMenuViewController;
呈现菜单视图控制器
[self.sideMenuViewController presentLeftMenuViewController];
或
[self.sideMenuViewController presentRightMenuViewController];
切换内容视图控制器
#import <RESideMenu/RESideMenu.h>
....
[self.sideMenuViewController setContentViewController:viewController animated:YES];
[self.sideMenuViewController hideMenuViewController];
RESideMenu
的一个子类。在这个示例中,我们称之为 DEMORootViewController
。DEMORootViewController
。DEMORootViewController.h
中导入 #import "RESideMenu.h"
。awakeFromNib
方法添加到 DEMORootViewController.m
中,代码如下:- (void)awakeFromNib
{
self.contentViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"contentViewController"];
self.leftMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"leftMenuController"];
self.rightMenuViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"rightMenuController"];
}
您可以自定义以下 RESideMenu
属性
@property (assign, readwrite, nonatomic) NSTimeInterval animationDuration;
@property (strong, readwrite, nonatomic) UIImage *backgroundImage;
@property (assign, readwrite, nonatomic) BOOL panGestureEnabled;
@property (assign, readwrite, nonatomic) BOOL panFromEdge;
@property (assign, readwrite, nonatomic) NSUInteger panMinimumOpenThreshold;
@property (assign, readwrite, nonatomic) BOOL interactivePopGestureRecognizerEnabled;
@property (assign, readwrite, nonatomic) BOOL scaleContentView;
@property (assign, readwrite, nonatomic) BOOL scaleBackgroundImageView;
@property (assign, readwrite, nonatomic) BOOL scaleMenuView;
@property (assign, readwrite, nonatomic) BOOL contentViewShadowEnabled;
@property (assign, readwrite, nonatomic) UIColor *contentViewShadowColor;
@property (assign, readwrite, nonatomic) CGSize contentViewShadowOffset;
@property (assign, readwrite, nonatomic) CGFloat contentViewShadowOpacity;
@property (assign, readwrite, nonatomic) CGFloat contentViewShadowRadius;
@property (assign, readwrite, nonatomic) CGFloat contentViewScaleValue;
@property (assign, readwrite, nonatomic) CGFloat contentViewInLandscapeOffsetCenterX;
@property (assign, readwrite, nonatomic) CGFloat contentViewInPortraitOffsetCenterX;
@property (assign, readwrite, nonatomic) CGFloat parallaxMenuMinimumRelativeValue;
@property (assign, readwrite, nonatomic) CGFloat parallaxMenuMaximumRelativeValue;
@property (assign, readwrite, nonatomic) CGFloat parallaxContentMinimumRelativeValue;
@property (assign, readwrite, nonatomic) CGFloat parallaxContentMaximumRelativeValue;
@property (assign, readwrite, nonatomic) CGAffineTransform menuViewControllerTransformation;
@property (assign, readwrite, nonatomic) BOOL parallaxEnabled;
@property (assign, readwrite, nonatomic) BOOL bouncesHorizontally;
@property (assign, readwrite, nonatomic) UIStatusBarStyle menuPreferredStatusBarStyle;
@property (assign, readwrite, nonatomic) BOOL menuPrefersStatusBarHidden;
如果您设置了背景图,别忘了将菜单视图控制器的背景色设置为清除色。
您可以通过实现 RESideMenuDelegate
协议来接收以下消息
- (void)sideMenu:(RESideMenu *)sideMenu didRecognizePanGesture:(UIPanGestureRecognizer *)recognizer;
- (void)sideMenu:(RESideMenu *)sideMenu willShowMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu didShowMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu willHideMenuViewController:(UIViewController *)menuViewController;
- (void)sideMenu:(RESideMenu *)sideMenu didHideMenuViewController:(UIViewController *)menuViewController;
Roman Efimov
RESideMenu遵循MIT许可。
版权所有 © 2013 Roman Efimov。
在此特此免费地向任何获得此软件和相关文档副本(统称为"软件")的人授予在此软件上不受限制地处理的权利,包括但不限于使用、复制、修改、合并、发布、分发、再许可和/或销售软件的副本,以及允许向其提供软件的人进行此类行为,前提是遵守以下条件:
上述版权声明和本使用许可声明应包括在软件的所有副本或主要部分的软件中。
该软件按"原样"提供,不提供任何明示或暗示的保证,包括但不限于适销性、适用于特定目的和非侵权性保证。在任何情况下,作者或版权所有者都无需对任何索赔、损害或其他责任负责,无论是基于合同、侵权或其他行为,不论是否存在与软件或其使用有关的事件、事实或情况。