侧滑抽屉MMDrawerController自定义侧滑手势

20 篇文章 0 订阅
9 篇文章 6 订阅

侧滑抽屉

https://github.com/mutualmobile/MMDrawerController#features

github上的一个开源侧滑框架,拥有自定义侧滑手势功能。但官方的文档只介绍了如何使用。没介绍如何自定义手势。使用MMDrawerController来实现菜单滑动效果。要求是每个一级页面是可以滑动的,二级页面是不允许滑动的。那就需要自定义侧滑手势了。


// 自定义侧滑手势
    [_drawerController setGestureShouldRecognizeTouchBlock:^BOOL(MMDrawerController *drawerController, UIGestureRecognizer *gesture, UITouch *touch) {

        BOOL shouldRecognizeTouch = NO;

        if(drawerController.openSide == MMDrawerSideNone &&

           [gesture isKindOfClass:[UIPanGestureRecognizer class]]){

            UITabBarController *tabVC = (UITabBarController *)drawerController.centerViewController;

            if([[(UINavigationController *)[tabVC selectedViewController] topViewController] isKindOfClass:[MainViewController class]] ||
               [[(UINavigationController *)[tabVC selectedViewController] topViewController] isKindOfClass:[ShoppingCartViewController class]] ||
               [[(UINavigationController *)[tabVC selectedViewController] topViewController] isKindOfClass:[VIPServicesViewController class]] ||
               [[(UINavigationController *)[tabVC selectedViewController] topViewController] isKindOfClass:[MessageViewController class]] ||
               [[(UINavigationController *)[tabVC selectedViewController] topViewController] isKindOfClass:[AccountDetailViewController class]]){//判断哪个控制器可以滑到抽屉

                shouldRecognizeTouch = YES;//返回yes表示可以滑动到左右侧抽屉

            }else{

                shouldRecognizeTouch = NO;

            }

            /*UIView * customView = [nav.topViewController view];

             CGPoint location = [touch locationInView:customView];//返回触摸点在view的坐标

             shouldRecognizeTouch = (CGRectContainsPoint(customView.bounds, location));//意思就是当point的位置在rect里面就返回yes,否则返回no*/

            NSLog(@"shouldRecognizeTouch==%d",shouldRecognizeTouch);

        }

        return shouldRecognizeTouch;

    }];

留个笔记以便查看

  • 2
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
您好!关于Android侧菜单,抽屉效果可以通过使用Android提供的DrawerLayout来实现。以下是一些基本的步骤: 1. 在您的布局文件中,使用DrawerLayout作为根布局,并将主要内容和侧菜单分别放置在该布局中的两个子布局中。 ```xml <androidx.drawerlayout.widget.DrawerLayout xmlns:android="http://schemas.android.com/apk/res/android" android:id="@+id/drawer_layout" android:layout_width="match_parent" android:layout_height="match_parent"> <!-- 主要内容 --> <LinearLayout android:layout_width="match_parent" android:layout_height="match_parent"> <!-- Your main content here --> </LinearLayout> <!-- 侧菜单 --> <LinearLayout android:id="@+id/drawer" android:layout_width="240dp" android:layout_height="match_parent" android:layout_gravity="start"> <!-- Your drawer content here --> </LinearLayout> </androidx.drawerlayout.widget.DrawerLayout> ``` 2. 在Java代码中,找到DrawerLayout并设置监听器以响应侧手势。 ```java DrawerLayout drawerLayout = findViewById(R.id.drawer_layout); ActionBarDrawerToggle toggle = new ActionBarDrawerToggle( this, drawerLayout, toolbar, R.string.open_drawer, R.string.close_drawer); drawerLayout.addDrawerListener(toggle); toggle.syncState(); ``` 3. 在您的manifest文件中,确保您的活动具有适当的主题,并且已启用ActionBar。 ```xml <activity ... android:theme="@style/AppTheme.NoActionBar"> ... </activity> ``` 这样,您就可以在您的应用程序中实现一个简单的侧菜单抽屉效果了。您可以在侧菜单中放置您的导航菜单或其他相关内容。希望这能帮到您!如果还有其他问题,请随时提问。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值