早睡早起,方能养生
Sleep early rise early, way to keep healthy

uniapp自定义导航栏 获取IOS及Android端顶部距离

super
2021-10-12 11:27
views 3730

data() {
	return {
		statusBarHeight: 0,
		viptop: 0
	}
},
onLoad() {
	// 适配 胶囊的上边距 安卓为6 苹果为4
	let int = uni.getSystemInfoSync().system.substr(0, 3) == 'IOS' ? 4 : 6;
	this.statusBarHeight = uni.getSystemInfoSync()['statusBarHeight'] + int;
	// 适配下方的外边距
	this.viptop = uni.getMenuButtonBoundingClientRect().height + this.statusBarHeight
}

 

IOS带留海的效果

 

 

小程序开发者工具Android效果

 

 

效果非常nice

 

小程序开发者工具iphone X 有点不齐

 

 

暂时找不到iphone X手机,无法在真机上测试



分享
0 条讨论
top