【问题标题】:Implement SWRevealViewController on only one UITabBarItem仅在一个 UITabBarItem 上实现 SWRevealViewController
【发布时间】:2023-03-03 15:27:01
【问题描述】:

我通过情节提要使用 UITabbarController 实现 SWRevealViewController。 我只想在第一个 UITabBarItem 中显示 SWRevealViewController,在其他 UITabBarItem 中我不想打开 SWRevealViewController,这完全完成了。 但问题是出现 SWRevealViewController 时,UITabBar 的位置并没有像 viewcontroller 那样改变。

请帮帮我。

故事板结构

【问题讨论】:

标签: ios objective-c uitabbarcontroller uitabbar swrevealviewcontroller


【解决方案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);
}

【讨论】:

    猜你喜欢
    • 2014-09-02
    • 2016-04-15
    • 1970-01-01
    • 2016-12-07
    • 2017-01-22
    • 2017-03-04
    • 1970-01-01
    • 2018-11-21
    • 1970-01-01
    相关资源
    最近更新 更多