skip to Main Content

How can we detect the size and changes of the iPhone 14 pro dynamic-island?

Since the safe area provides a safe rectangle inside the rounded screen and top or bottom insets, but nothing about an object inside the rectangle.

The all we know about safe area:

enter image description here

2

Answers


  1. You can simply try to get the safe area top insets and use the dynamic height as you want.

    In my scenario, requirement was to change status bar background colour. So I did something like this:

        let window = UIApplication.shared.windows.first
        let topPadding = window?.safeAreaInsets.top
        let statusBar = UIView(frame: CGRect(x: 0, y: 0, width: UIScreen.main.bounds.size.width, height: topPadding ?? 0.0))
        statusBar.backgroundColor = UIColor(named: "AppPrimaryColor")
        UIApplication.shared.windows.filter {$0.isKeyWindow}.first?.addSubview(statusBar)
    

    Dynamic island is fun to play with. screen shot

    Login or Signup to reply.
  2. First of all for most developers it is sufficient to use safeArea as we did before, because dynamic island does not cover it (if not in expanded state). There are currently 3 states of fynamic island:

    1. Compact. In the Dynamic Island, the system uses the compact presentation when there’s only one Live Activity that’s currently active.
      compact state
    2. Minimal. When multiple Live Activities are active, the system uses the minimal presentation to display two of them in the Dynamic Island. One Live Activity appears attached to the Dynamic Island while the other appears detached.

    minimal

    1. Expanded. When people touch and hold a Live Activity in a compact or minimal presentation, the system displays the content in an expanded presentation.

    enter image description here

    You can check each state if you use dynamic island yourself as part WidgetKit. Create a new widget extension if your app doesn’t already include one. Live Activities use WidgetKit functionality and SwiftUI for their user interface. For creating new Activities, please refer to Apple official documentation for Displaying live data with Live Activities.
    If you are not intending to use Activities, but want to somehow be aware of dynamic island available sizes, Apple provides as with Dynamic island size sheet included in Live Activities documentation :

    dynamic island size sheet

    Here is an attachment of how safeArea looks implemented with dynamic island:

    safe are with dynamic island

    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search