MatchedGeometryEffect + URL-адрес изображения
Может кто-нибудь объяснить, почему MatchedGeometryEffect работает с изображениями из папки ресурсов, но не с URL-адресами? И как нам обойти это, чтобы мы могли использовать MatchedGeometryEffect с реальными изображениями?
Видео с изображением (работает): https://imgur.com/rI4VcsP
Видео с изображением из URL (не работает): https://imgur.com/0KfGHRj
Код:
import SwiftUI
import Kingfisher
struct ZStackView: View {
@StateObject private var VM = ViewModel()
@Namespace private var nsspace
@State private var selectedProfile: Profile?
var body: some View {
ZStack {
ForEach(Array(zip(VM.profiles.indices, VM.profiles)), id: \.1) { index, profile in
if Int(index) == 0 {
VStack {
ScrollView {
Text(profile.name)
.font(.largeTitle)
if selectedProfile == nil {
//Image("tower") // works
KFImage(profile.urls.first) // doesnt work
.resizable()
.scaledToFill()
.matchedGeometryEffect(id: profile.id, in: nsspace)
.frame(width: 300, height: 400)
.clipped()
.onTapGesture {withAnimation(.easeInOut) {
VM.profiles.removeAll(where: { $0.id == profile.id})
}}
}
Text(profile.prompt)
.font(.largeTitle)
.onTapGesture {
withAnimation {
selectedProfile = profile
}
}
}
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.zIndex(1)
.transition(AnyTransition.asymmetric(insertion: .scale, removal: .move(edge: .leading)))
}
}
if let profile = selectedProfile {
VStack {
//Image("tower") // works
KFImage(profile.urls.first) // doesnt work
.resizable()
.scaledToFill()
.matchedGeometryEffect(id: profile.id, in: nsspace)
.frame(width: 300, height: 400)
.clipped()
}
.frame(maxWidth: .infinity, maxHeight: .infinity)
.background(content: {
Color.blue
})
.onTapGesture {
withAnimation {
selectedProfile = nil
}
}
.zIndex(2)
}
}
}
}
1 ответ
Порядок применения модификатора имеет значение. Кроме того, по моему опыту,clipped()
не очень хорошо работает с эффектом.