首页 文章

仅在一个UITabBarItem上实现SWRevealViewController

提问于
浏览
8

我通过故事板实现了SWITeveViewController和UITabbarController . 我想在第一个UITabBarItem中显示SWRevealViewController,在其他UITabBarItem中我不想打开完全完成的SWRevealViewController . 但问题是当SWRevealViewController出现时,UITabBar的位置不像viewcontroller那样改变 .

请帮我 .

enter image description here

Storyboard structure
enter image description here

1 回答

  • 1

    我通过使用 SWRevealViewController 委托方法手动更改 UITabbar 的位置来解决问题 . 将此代码放在 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);
    }
    

相关问题