Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to find out the distance from the bottom safe area edge to the bottom of the screen?

I need to calculate the distance between the bottom anchor of the safe area and the bottom of the screen. Is there a way to do that in code given a view?

enter image description here

like image 652
Evgenii Avatar asked Nov 18 '17 23:11

Evgenii


People also ask

What is a safe area iOS?

The safe area represents the portion of your screen that is unobscured by bars and other operating system based content. Safe area is pre-defined by iOS across all Apple devices and is present in Android devices as well.

How do I get Safeareainsets?

You obtain the safe area for a view by applying the insets in this property to the view's bounds rectangle. If the view is not currently installed in a view hierarchy, or is not yet visible onscreen, the edge insets in this property are 0.

What is Safearea Swift?

A safe area defines the area within a view that isn't covered by a navigation bar, tab bar, toolbar, or other views. SwiftUI views respect safe areas out of the box. But there are plenty of situations when you need to customize this behavior.


1 Answers

Try this one

if #available(iOS 11.0, *) {
    let window = UIApplication.shared.keyWindow
    let bottomPadding = window?.safeAreaInsets.bottom
}
like image 185
user6788419 Avatar answered Sep 27 '22 22:09

user6788419