0

我正在尝试使用 AsyncImage 异步加载图像 - 但结果是图像非常大并且覆盖了所有屏幕。

        TabView { 
         CreateView()
            .tabItem {
                Image(systemName: "plus.circle")
            }
        
         AccountView()
            .tabItem {
                let imageUrl = LoginManager.shared.profile!.profileImageUrl
                
                ZStack {
                    AsyncImage(url: URL(string: imageUrl)) { phase in
                        switch phase {
                        case .empty:
                            ProgressView()
                        case .success(let image):
                            image.resizable()
                                .aspectRatio(contentMode: .fit)
                                .frame(maxWidth: 56, maxHeight: 56)
                        case .failure:
                            Image(systemName: "person.circle")
                        @unknown default:
                            // Since the AsyncImagePhase enum isn't frozen,
                            // we need to add this currently unused fallback
                            // to handle any new cases that might be added
                            // in the future:
                            EmptyView()
                        }
                    }
                    .frame(width: 50, height: 50)
                }
                .frame(maxWidth: 56, maxHeight: 56)
            }
    }

试图在每个地方放置 .frame 边界,但图像非常大!

我究竟做错了什么?

感谢您的协助!

4

0 回答 0