代码之家  ›  专栏  ›  技术社区  ›  Pramod Tapaniya

仅在一个UITabBarItem上实现SWRevealViewController

  •  8
  • Pramod Tapaniya  · 技术社区  · 8 年前

    我通过故事板用UITabbarController实现SWRevealViewController。 我只想在第一个UITabBarItem中显示SWRevealViewController,而在另一个UITab BarItem,我不想打开SWReveal ViewController,这完全完成了。 但问题是,当SWRevealViewController出现时,UITabBar的位置不会像viewcontroller一样改变。

    请帮帮我。

    enter image description here

    故事板结构 enter image description here

    1 回复  |  直到 7 年前
        1
  •  2
  •   Pramod Tapaniya    8 年前

    我通过改变位置来解决问题 UITabbar 手动使用 SWRevealViewController 委托方法。 输入此代码 MenuViewController .

    MenuViewController.m

    - (void) viewDidLoad {
        [super viewDidLoad];
    
        UITabBarController *tbc = (UITabBarController *)[[[[UIApplication sharedApplication]delegate]window]rootViewController];
        self.tabBar = tbc.tabBar;
    
        _tabBar.frame = CGRectMake(self.revealViewController.rearViewRevealWidth, _tabBar.frame.origin.y, _tabBar.frame.size.width, _tabBar.frame.size.height);
        self.revealViewController.delegate = self;
    }
    
    - (void) revealController:(SWRevealViewController *)revealController willMoveToPosition:(FrontViewPosition)position {
        if (position == FrontViewPositionRight) {
            _tabBar.frame = CGRectMake(self.revealViewController.rearViewRevealWidth, _tabBar.frame.origin.y, _tabBar.frame.size.width, _tabBar.frame.size.height);
        }
        else {
            _tabBar.frame = CGRectMake(0, _tabBar.frame.origin.y, _tabBar.frame.size.width, _tabBar.frame.size.height);
        }
    }
    
    - (void)revealController:(SWRevealViewController *)revealController panGestureMovedToLocation:(CGFloat)location progress:(CGFloat)progress overProgress:(CGFloat)overProgress {
        _tabBar.frame = CGRectMake(self.revealViewController.rearViewRevealWidth * progress, _tabBar.frame.origin.y, _tabBar.frame.size.width, _tabBar.frame.size.height);
    }