【问题标题】:iOS 13 UITabBar RePosition to TopiOS 13 UITabBar 重新定位到顶部
【发布时间】:2019-08-22 11:02:41
【问题描述】:

我已关注this answer 将我的标签栏重新定位到页面顶部。在 iOS 13 发布之前,它一直运行良好。在 iOS 13 中,标签栏在屏幕底部可见。我应该使用任何其他解决方法吗?

有人遇到同样的问题吗?

更新:

以下是我在应用中使用的代码:

- (void) viewWillLayoutSubviews {
    [super viewWillLayoutSubviews];
    [self.tabBar invalidateIntrinsicContentSize];

    // Just a quick fix for making this to happen for iOS versions between 11.0 to 11.1
    // Updating the frame in Main queue.
    dispatch_async(dispatch_get_main_queue(), ^{
        [self changeTabBarPosition];
    });

    // Set the translucent property to NO then back to YES to
    // force the UITabBar to reblur, otherwise part of the
    // new frame will be completely transparent if we rotate
    // from a landscape orientation to a portrait orientation.

    self.tabBar.translucent = NO;
    self.tabBar.translucent = YES;
}

- (void)changeTabBarPosition {
    CGFloat tabSize = 44.0;
    UIInterfaceOrientation orientation = [UIApplication sharedApplication].statusBarOrientation;
    if (UIInterfaceOrientationIsLandscape(orientation)) {
        tabSize = 32.0;
    }
    CGRect tabFrame = self.tabBar.frame;
    tabFrame.size.height = tabSize;
    tabFrame.origin.y = [UIApplication sharedApplication].statusBarFrame.size.height;
    self.tabBar.frame = tabFrame;
}

【问题讨论】:

  • 实际上 statusBarOrientation 在 iOS 13 中已被弃用。因此请检查并更新您的代码。显示您尝试过的代码
  • 我们怎么知道你尝试了哪一个

标签: ios objective-c ios13 xcode11


【解决方案1】:

我在他/她的回答中提到的@Thanh Vu 的帮助下找到了解决方案。下面的代码解决了我的问题。

- (void) viewDidLayoutSubviews {
    [super viewDidLayoutSubviews];

    [self.tabBar invalidateIntrinsicContentSize];

    CGRect tabFrame = self.tabBar.frame;
    tabFrame.size.height = 44.0;
    tabFrame.origin.y = 0;
    self.tabBar.frame = tabFrame;

    // Set the translucent property to NO then back to YES to
    // force the UITabBar to reblur, otherwise part of the
    // new frame will be completely transparent if we rotate
    // from a landscape orientation to a portrait orientation.
    self.tabBar.translucent = NO;
    self.tabBar.translucent = YES;
}

【讨论】:

    【解决方案2】:

    我只是在 iOS 13 上测试了下面的代码。它仍然可以工作。

    - (void)viewDidLayoutSubviews {
      [super viewDidLayoutSubviews];
      self.tabBarController.tabBar.frame = CGRectMake(0, 0, self.view.frame.size.width, self.tabBarController.tabBar.frame.size.height);
    }
    

    【讨论】:

    • 换框后打电话[super viewDidLayoutSubViews];感觉不好。
    【解决方案3】:

    经过一番努力,我也得到了这个解决方案,使用 Swift5 + IOS13.2Sdk。 Follow this answer.

    class MyUITabBarController:UITabBarController{
        override func viewDidLayoutSubviews(){
            super.viewDidLayoutSubviews()
            var frame = self.tabBar.frame
            frame.origin.y = 0
            self.tabBar.frame = frame
        }
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2021-05-11
      • 2012-12-31
      • 2015-04-09
      • 1970-01-01
      • 2011-10-01
      相关资源
      最近更新 更多