【问题标题】:Swift View Layout below tabbar标签栏下方的 Swift 视图布局
【发布时间】:2016-10-07 18:02:04
【问题描述】:
class AppDelegate: UIResponder, UIApplicationDelegate {

var window: UIWindow?

func application(application: UIApplication, didFinishLaunchingWithOptions launchOptions: [NSObject: AnyObject]?) -> Bool {
    self.window = UIWindow(frame: UIScreen.mainScreen().bounds)
    self.window?.backgroundColor = UIColor.whiteColor()
    self.window?.makeKeyAndVisible()

    let vc = ViewController()
    vc.tabBarItem = UITabBarItem(...)
    ...
    let tabbar = UITabBarController()
    tabbar.setViewControllers([...,vc,...], animated: false)

    self.window?.rootViewController = tabbar

    tabbar.selectedIndex = 2
    return true
   }
}
class ViewController: UIViewController {
    override func loadView() {
        super.loadView()
        self.view.backgroundColor = UIColor.yellowColor()
        //self.automaticallyAdjustsScrollViewInsets = false;
    }

    override func viewDidLoad() {
        super.viewDidLoad()
    }

    override func viewDidAppear(animated: Bool) {
         super.viewDidAppear(animated)
  }
}

我没有使用故事板。

以上导致ViewControllers 视图延伸到标签栏下方。我怎样才能阻止这种情况?

我尝试将视图框架设置为

CGRectMake(0, 0, self.view.frame.width, self.view.frame.height - tabBarController.view.frame.height))

但这没有用。

【问题讨论】:

    标签: ios swift uiviewcontroller ios9 uitabcontroller


    【解决方案1】:

    您可以使用UIViewControlleredgesForExtendedLayout 属性来设置在导航栏下延伸哪些边缘。如果你不想要,你可以简单地说:

    self.edgesForExtendedLayout = .None
    

    【讨论】:

      【解决方案2】:

      适用于 Swift 5 或更高版本

      self.edgesForExtendedLayout = []
      

      【讨论】:

        猜你喜欢
        • 2015-02-03
        • 2016-06-30
        • 1970-01-01
        • 2017-11-26
        • 1970-01-01
        • 1970-01-01
        • 2016-07-26
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多