iOS抽屉效果和侧边菜单

iOS抽屉效果和侧边菜单

源码下载地址

1、效果演示

1. 抽屉效果演示

1. 侧边菜单演示

2、使用说明

构造方法 initialization

/// 构造方法(左控制器 & 右控制器 & 背景图片)
-(instancetype)initWithLeftController:(UIViewController *)leftController
                    andMainController:(UIViewController *)mainController
                   andRightController:(UIViewController *)rightController
                   andBackgroundImage:(UIImage *)image;

/// 构造方法(左控制器 & 右控制器)
-(instancetype)initWithLeftController:(UIViewController *)leftController
                    andMainController:(UIViewController *)mainController
                   andRightController:(UIViewController *)rightController;

/// 构造方法(左控制器 & 右控制器)
-(instancetype)initWithLeftController:(UIViewController *)leftController andMainView:(UIViewController *)mainController;

/// 构造方法(右控制器)
-(instancetype)initWithRightView:(UIViewController *)rightController andMainView:(UIViewController *)mainController;

视图控制方法 View control method

/// 恢复位置
-(void)showMainView;

/// 显示左视图
-(void)showLeftView;

/// 显示右视图
-(void)showRighView;

属性 attribute

/// 主视图隐藏后显示比例(0~1)
@property (nonatomic, assign) CGFloat otherScale;

/// 主视图比例 (0~1)
@property (nonatomic, assign) CGFloat mainScale;

/// 滑动速度系数-建议在0.5-1之间。默认为0.5
@property (assign,nonatomic) CGFloat speedf;

/// 是否允许点击视图恢复视图位置。默认为yes
@property (strong) UITapGestureRecognizer *sideslipTapGes;

3、使用方法

AppDelegate.m
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {

    // 1. 创建window
    self.window = [[UIWindow alloc] initWithFrame:[UIScreen mainScreen].bounds];

    // 2. 创建控制器
    MainController *main = [[MainController alloc] init];
    LeftController *left = [[LeftController alloc] init];
    RightController *right = [[RightController alloc] init];

    // 3. 创建跟控制器
    JRMenuController *controller = [[JRMenuController alloc] initWithLeftController:left andMainController:main andRightController:right];
    controller.mainScale = 0.8;
    controller.otherScale = 0.6;
    controller.speedf = 0.6;
    // 4. 设置跟控制器
    self.window.rootViewController = controller;

    // 5. 显示 window
    [self.window makeKeyAndVisible];

    return YES;
}

4、 知识点总结

1. 滑动手势方向判断

// 滑动方向
typedef NS_ENUM(NSInteger, CameraMoveDirection) {
    kCameraMoveDirectionNone,
    kCameraMoveDirectionUp,
    kCameraMoveDirectionDown,
    kCameraMoveDirectionRight,
    kCameraMoveDirectionLeft,
};
 //创建滑动手势
        UIPanGestureRecognizer * pan = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(handleSwipe:)];
#pragma mark - 判断滑动方向
- ( void )handleSwipe:( UIPanGestureRecognizer *)gesture {

    CGPoint translation = [gesture translationInView: self.view];

    if (gesture.state == UIGestureRecognizerStateBegan )
    {
        self.direction = kCameraMoveDirectionNone;
    }

    else if (gesture.state == UIGestureRecognizerStateChanged && self.direction == kCameraMoveDirectionNone)
    {
        // 获取 方向
        self.direction = [ self determineCameraDirectionIfNeeded:translation];
    }

    if (self.direction == kCameraMoveDirectionRight && self.leftControl != nil) {

        [self handlePan:gesture];
    }

    if (self.direction == kCameraMoveDirectionLeft && self.righControl != nil) {

        [self handlePan:gesture];
    }
}
// 获取方向
- ( CameraMoveDirection )determineCameraDirectionIfNeeded:( CGPoint )translation
{
    if (self.direction != kCameraMoveDirectionNone)
        return self.direction;

    if (fabs(translation.x) > gestureMinimumTranslation)
    {
        BOOL gestureHorizontal = NO;
        if (translation.y == 0.0 )
            gestureHorizontal = YES;
        else
            gestureHorizontal = (fabs(translation.x / translation.y) > 5.0 );
        if (gestureHorizontal)
        {
            if (translation.x > 0.0 )
                return kCameraMoveDirectionRight;
            else
                return kCameraMoveDirectionLeft;
        }
    }

    else if (fabs(translation.y) > gestureMinimumTranslation)

    {
        BOOL gestureVertical = NO;
        if (translation.x == 0.0 )
            gestureVertical = YES;
        else
            gestureVertical = (fabs(translation.y / translation.x) > 5.0 );
        if (gestureVertical)

        {
            if (translation.y > 0.0 )

                return kCameraMoveDirectionDown;
            else
                return kCameraMoveDirectionUp;
        }
    }
    return self.direction;
}

2. 滑动手势和tableview滑动共存

#pragma mark - UIGestureRecognizerDelegate
// 设置手势 滑动 和 tableView 滚动并存
- (BOOL)gestureRecognizer:(UIGestureRecognizer *)gestureRecognizer shouldRecognizeSimultaneouslyWithGestureRecognizer:(UIGestureRecognizer *)otherGestureRecognizer {

    if ([otherGestureRecognizer.view isKindOfClass:[UITableView class]]) {
        return YES;
    }
    return NO;
}

3. tableviewcell 分割线设置贯穿整个tableView(补充)

// cell 行分割线 设置
- (void)tableView:(UITableView *)tableView willDisplayCell:(UITableViewCell *)cell forRowAtIndexPath:(NSIndexPath *)indexPath {

    if ([cell respondsToSelector:@selector(setSeparatorInset:)]) {
        [cell setSeparatorInset: UIEdgeInsetsZero];
    }

    if ([cell respondsToSelector:@selector(setLayoutManager:)]) {
        [cell setLayoutMargins:UIEdgeInsetsZero];
    }
}

- (void)viewDidLayoutSubviews {

    if ([self.tableView respondsToSelector:@selector(setSeparatorInset:)]) {
         [self.tableView setSeparatorInset:UIEdgeInsetsMake(0,0,0,0)];
    }

    if ([self.tableView respondsToSelector:@selector(setLayoutMargins:)]) {
        [self.tableView setLayoutMargins:UIEdgeInsetsMake(0,0,0,0)];
    }
}
时间: 2024-10-24 14:53:34

iOS抽屉效果和侧边菜单的相关文章

Android 抽屉效果的导航菜单实现

抽屉效果的导航菜单 看了很多应用,觉得这种侧滑的抽屉效果的菜单很好. 不用切换到另一个页面,也不用去按菜单的硬件按钮,直接在界面上一个按钮点击,菜单就滑出来,而且感觉能放很多东西. 关于实现,搜索了一下,有如下两种: 1.用SlidingDrawer: http://developer.android.com/reference/android/widget/SlidingDrawer.html 但是不知道为什么这个类官方不建议再继续用了: Deprecated since API level

IOS抽屉效果功能实现

抽屉效果功能实现 一..h文件 @interface HMDrawViewController : UIViewController @property (nonatomic, weak, readonly) UIView *mainView;@property (nonatomic, weak, readonly) UIView *leftView;@property (nonatomic, weak, readonly) UIView *rightView; @end 二..m文件 @int

iOS抽屉效果

源码下载 抽屉效果第三方类库下载 所需第三方类库下载 侧拉栏抽屉效果图         需要导入的头文件: #import "MMDrawerController.h" #import "MMExampleDrawerVisualStateManager.h" 代码实现: 首先需要创建三个试图控制器 //主视图 FirstViewController *firstVC = [[FirstViewController alloc] init]; //左边视图 Seco

IOS 抽屉效果

原创Blog,转载请注明出处 blog.csdn.net/hello_hwc 先看看Demo效果 视频链接如下 http://v.youku.com/v_show/id_XODc1OTQwODQ0.html 实现过程如下 1 新建一个基于单视图的工程.拖入两个ViewController,为了区分,在大纲中改为firstViewController 和 SecondViewController.沿着图中红线control+拖拽,在弹出的窗口中选择Show 2 选择Segue,为其添加Identi

猫猫学IOS(二十六)UI之iOS抽屉效果小Demo

猫猫分享,必须精品 素材代码地址:http://blog.csdn.net/u013357243/article/details/45305785 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 先看效果 实现过程 第一步,把三个view设置好,还有颜色 #warning 第一步 - (void)addChildView { // left UIView *leftView = [[UIVie

(素材源码)猫猫学IOS(二十六)UI之iOS抽屉效果小Demo

猫猫分享,必须精品 素材代码地址:http://download.csdn.net/detail/u013357243/8635679 原创文章,欢迎转载.转载请注明:翟乃玉的博客 地址:http://blog.csdn.net/u013357243?viewmode=contents 先看效果 源码 NYDrawViewController.h // // NYDrawViewController.h // 06-抽屉效果 // // Created by apple on 14-9-1. /

简单的iOS抽屉效果

#define screenW [UIScreen mainScreen].bounds.size.width #import "ViewController.h" @interface ViewController () @property (nonatomic,strong)UIView * redView; @property (nonatomic,strong)UIView *yellowView; @property (nonatomic,strong)UIView *gre

android.support.v4.widget.DrawerLayout 抽屉效果导航菜单

抽屉效果导航菜单图示 如图所示,抽屉效果的导航菜单不用切换到另一个页面,也不用去按菜单的硬件按钮,直接在界面左上角的一个按钮点击,菜单就滑出来,而且感觉能放很多东西 概况:实现上图所示的抽屉效果的导航菜单有以下两种方式 方式1.用SlidingDrawer: http://developer.android.com/reference/android/widget/SlidingDrawer.html 但是不知道为什么这个类官方不建议再继续用了: Deprecated since API lev

抽屉效果学习

1, Ios左右菜单PPRevealSideviewController使用的一些心得 代码编写 http://blog.csdn.net/qjlhlh/article/details/8204563 2 stoaryBoard编写 iOS抽屉效果的demo http://cache.baiducontent.com/c?m=9f65cb4a8c8507ed4fece7631046893b4c4380146d96864968d4e414c42246071a27a2b820260d57938327