Эффект согласованной геометрии не работает с окномIOS

Программируем под IOS
Ответить Пред. темаСлед. тема
Гость
 Эффект согласованной геометрии не работает с окном

Сообщение Гость »


I have a square that is embedded within a scroll view inside a subview. When the square is clicked I want to animate it to the top of the view hierarchy and present it above everything else using a matched geometry effect. I cannot get the animation to work. When the square presented at the top is dismissed it should animate back down to the original view.

Problem I present the square at the top of the view hierarchy through a window which makes the animation fail. How can I correctly animate with a window? How can I add basic match geometry effects, transitions, and other animations with windows?

Код: Выделить всё

struct SomeView: View {     @EnvironmentObject var popRoot: PopToRoot     @Namespace private var animation     var body: some View {         ScrollView {             RoundedRectangle(cornerRadius: 10)                 .matchedGeometryEffect(id: "squareAnim", in: animation)                 .foregroundStyle(.blue).frame(width: 50, height: 50)                 .onTapGesture {                     withAnimation {                         popRoot.showOverlay = true                     }                 }             //other sub views         }     } } struct ContentView: View { //top of view hierarchy      @EnvironmentObject var popRoot: PopToRoot      @Namespace private var animation      var body: some View {           SomeView()              .overlay {                     if showOverlay {                         TopViewWindow()                             .matchedGeometryEffect(id: "squareAnim", in: animation)                             // ----- HERE                     }              }      } } class PopToRoot: ObservableObject { //envirnment object to be accessed anywhere     @Published var showOverlay = false } 
video player that goes above everything

Код: Выделить всё

struct TopView: View {     var body: some View {         ZStack {             RoundedRectangle(cornerRadius: 10)                 .foregroundStyle(.blue).frame(width: 100, height: 100)                          //other views         }.ignoresSafeArea()     } } struct TopViewWindow: View {     @State private var hostingController: UIHostingController? = nil     func showImage() {         let swiftUIView = TopView()         hostingController = UIHostingController(rootView: swiftUIView)         hostingController?.view.backgroundColor = .clear         hostingController?.view.frame = CGRect(             x: 0,             y: 0,             width: UIScreen.main.bounds.width,             height: UIScreen.main.bounds.height)         if let windowScene = UIApplication.shared.connectedScenes.first as? UIWindowScene,            let window = windowScene.windows.first {             // withAnimation { doesnt work here either             window.addSubview(hostingController!.view)             hostingController?.view.center.x = window.center.x         }     }     func dismissImage() {         hostingController?.view.removeFromSuperview()         hostingController = nil     }     var body: some View {         VStack {}.onAppear { showImage() }.onDisappear { dismissImage() }     } } 


Источник: https://stackoverflow.com/questions/780 ... ith-window
Реклама
Ответить Пред. темаСлед. тема

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

  • Похожие темы
    Ответы
    Просмотры
    Последнее сообщение
  • Эффект согласованной геометрии не работает с окном
    Anonymous » » в форуме IOS
    0 Ответы
    29 Просмотры
    Последнее сообщение Anonymous
  • Нежелательный эффект кроссфейда в эффекте согласованной геометрии SwiftUI
    Anonymous » » в форуме IOS
    0 Ответы
    41 Просмотры
    Последнее сообщение Anonymous
  • Эффект согласованной геометрии анимируется неправильно.
    Anonymous » » в форуме IOS
    0 Ответы
    29 Просмотры
    Последнее сообщение Anonymous
  • Эффект согласованной геометрии анимируется неправильно.
    Anonymous » » в форуме IOS
    0 Ответы
    49 Просмотры
    Последнее сообщение Anonymous
  • Эффект согласованной геометрии в одну сторону
    Anonymous » » в форуме IOS
    0 Ответы
    35 Просмотры
    Последнее сообщение Anonymous

Вернуться в «IOS»