zoukankan      html  css  js  c++  java
  • iOS开发--SWRevealViewController

    SWRevealViewController 是一个比较好的实现Sliding功能的第三方类。

    今天跟大家分享一下如何使用SWRevealViewController实现左右菜单滑动功能。

    首先,在工程中创建三个类,依次为 RootViewController、LeftViewController、RightViewController。

    在工程中添加SWRevealViewController类以及所需要的图片。

    在AppDelegate中添加如下代码:

    [objc] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. RootViewController* rootViewController = [[RootViewController alloc] init];  
    2.     UINavigationController* navigationController = [[UINavigationController alloc] initWithRootViewController:rootViewController];  
    3.       
    4.     LeftViewController* leftViewController = [[LeftViewController alloc] init];  
    5.     RightViewController* rightViewController = [[RightViewController alloc] init];  
    6.       
    7.     SWRevealViewController* revealViewController = [[SWRevealViewController alloc] initWithRearViewController:leftViewController frontViewController:navigationController];  
    8.     [revealViewController setRightViewController:rightViewController];  
    9.       
    10.     self.window.rootViewController = revealViewController;  


    然后在RootViewController中添加按钮触发事件:

    [html] view plain copy
     在CODE上查看代码片派生到我的代码片
    1. SWRevealViewController *revealController = self.revealViewController;  
    2.     UIButton* leftButton = [self navigationButtonWithTitle:nil image:[UIImage imageNamed:@"ico_home_menu"] target:revealController action:@selector(revealToggle:)];  
    3.     UIBarButtonItem* leftBarButton = [[UIBarButtonItem alloc] initWithCustomView:leftButton];  
    4.     self.navigationItem.leftBarButtonItem = leftBarButton;  
    5.       
    6.     UIButton* rightButton = [self navigationButtonWithTitle:nil image:[UIImage imageNamed:@"ico_home_menu"] target:revealController action:@selector(rightRevealToggle:)];  
    7.     UIBarButtonItem* rightBarButton = [[UIBarButtonItem alloc] initWithCustomView:rightButton];  
    8.     self.navigationItem.rightBarButtonItem = rightBarButton;  


    这就完成了利用SWRevealViewController实现滑动效果的全部代码。

  • 相关阅读:
    Vim step by step
    Ubuntu解压命令全览
    这样才能使本地Mysql服务允许被外部主机连接(两步)
    [Python] logging.logger
    Python Selenium
    MySQL中char、varchar和text的区别
    Way to MongoDB
    Python误区之strip,lstrip,rstrip
    Android Studio Tips
    Way to tmux
  • 原文地址:https://www.cnblogs.com/wanghuaijun/p/5415990.html
Copyright © 2011-2022 走看看