1
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))

但这没有用。

4

2 回答 2

4

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

self.edgesForExtendedLayout = .None
于 2016-06-07T18:47:18.930 回答
0

Swift 5或更高版本

self.edgesForExtendedLayout = []
于 2021-07-08T16:58:23.750 回答