最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

ios - How to fit an image into a dynamic notch? - Stack Overflow

programmeradmin0浏览0评论

I want to place images in dynamic notch in Swift UI. I put 2 images using Z stack. The 2nd image represents the image that will come to dynamic notch but it does not fit exactly in dynamic notch. How should I draw a view? Thanks.

Notch Screenshot

ZStack {
        GeometryReader { geometry in
            Image(uiImage: UIImage(named: "bgImage")!)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: geometry.size.width, alignment: .center)
                .frame(height: UIScreen.main.bounds.height)
        }
        VStack {
            Image(uiImage: UIImage(named: "notch")!)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: UIScreen.main.bounds.width)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
    }
    .ignoresSafeArea()

I want to place images in dynamic notch in Swift UI. I put 2 images using Z stack. The 2nd image represents the image that will come to dynamic notch but it does not fit exactly in dynamic notch. How should I draw a view? Thanks.

Notch Screenshot

ZStack {
        GeometryReader { geometry in
            Image(uiImage: UIImage(named: "bgImage")!)
                .resizable()
                .aspectRatio(contentMode: .fill)
                .frame(width: geometry.size.width, alignment: .center)
                .frame(height: UIScreen.main.bounds.height)
        }
        VStack {
            Image(uiImage: UIImage(named: "notch")!)
                .resizable()
                .aspectRatio(contentMode: .fit)
                .frame(width: UIScreen.main.bounds.width)
        }
        .frame(maxWidth: .infinity, maxHeight: .infinity, alignment: .top)
    }
    .ignoresSafeArea()
Share Improve this question edited Mar 12 at 21:02 Aproachate asked Mar 12 at 21:02 AproachateAproachate 13 bronze badges 2
  • I think that can only be done with LiveActivities. – lorem ipsum Commented Mar 12 at 21:36
  • Some apps do this without using live activities but I don't understand how they do it. – Aproachate Commented Mar 13 at 19:57
Add a comment  | 

1 Answer 1

Reset to default 0

I think GeometryReader dynamicIsland is not working as expected. That's why the image might not look the way you want it to.

发布评论

评论列表(0)

  1. 暂无评论