Ionic tab bar overlaps home button (iPhone X - iOS 11)

拜拜、爱过 提交于 2019-12-06 22:16:36

问题


With iOS 11 and iPhone X Apple specified every app should live in a "safe area" (due to the virtual home button):

Inset essential content to prevent clipping. [...] For best results, use standard, system-provided interface elements and Auto Layout to construct your interface. All apps should adhere to the safe area and layout margins defined by UIKit, which ensure appropriate insetting based on the device and context. The safe area also prevents content from underlapping the status bar, navigation bar, toolbar, and tab bar.

The problem is a Ionic app (v. 1) with tab bar cover this part of the screen, therefore the bar is under the home button:

Does anyone know how to fix it?

(please note: if you run a new Ionic app v1 inside iPhone X simulator you will get two black spaces, at the top and bottom of the window, but you can prevent this adding "viewport-fit=cover" to your meta tag inside index.html)


回答1:


For an Ionic1 project, I found that targeting the tab-nav did the trick.

.tab-nav {
    margin-bottom: constant(safe-area-inset-bottom);
}



回答2:


You should be able to apply the same principle outlined in this answer to the Ionic v1 footer, i.e.

.bar-footer {
    margin-bottom: constant(safe-area-inset-bottom);
}

(or something similar - I haven't tested this)




回答3:


For an Ionic 4 project, this would be:
app.scss

body {
  margin-top: env(safe-area-inset-top);
  margin-top: constant(safe-area-inset-top);
}

ion-tab-bar {
  margin-bottom: env(safe-area-inset-bottom);
}

env is for more recent iOS11 versions, and constant is for older ones.




回答4:


You can add a constraint to your custom tabBar main view to connect it to the bottom safeAreaLayoutGuide.

yourView.bottomAnchor.constraint(equalTo: self.view.safeAreaLayoutGuide.bottomAnchor).isActive = true


来源:https://stackoverflow.com/questions/46322419/ionic-tab-bar-overlaps-home-button-iphone-x-ios-11

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!