SwiftUI:放大手势不会触发

时间:2019-07-31 16:05:20

标签: swiftui

我想在屏幕上添加一个MagnificationGesture,但不会触发。我尝试通过.gesturesimultaneousGesture等添加手势,但没有区别。在我看来,滚动视图的手势具有优先权,但我不知道如何同时识别两个手势。

...
@State private var magnification: CGFloat = 1.0

var body: some View {

        let magnificationGesture = MagnificationGesture(minimumScaleDelta: 0)
            .onChanged({ value in

                self.magnification = value
            })
            .onEnded({ value in

                self.magnification = value
            })

        return Group {

            VStack {

                TitleView(title: NSLocalizedString("timeline.title", comment: ""))

                ScaleView(viewModel: viewModel)

                ScrollView(.horizontal) {

...
                }

                Text("\(String(describing: magnification))")
            }
        }
        .gesture(magnificationGesture)
    }

编辑:我创建了一个具有相同错误行为的独立变体:

//
//  TimelineMock.swift
//  Testprojekt
//
//  Created by Gerhard Schneider on 31.07.19.
//  Copyright © 2019 innoreq GmbH. All rights reserved.
//

import SwiftUI


struct TimelineView: View {


    @State private var magnification: CGFloat = 1.0


    var body: some View {

        let magnificationGesture = MagnificationGesture(minimumScaleDelta: 0)
            .onChanged({ value in

                self.magnification = value
            })
            .onEnded({ value in

                self.magnification = value
            })

        return Group {

            VStack {

                Text("Title")
                .foregroundColor(.red)

                ScrollView(.horizontal) {

                    ZStack {

                        ForEach(0 ..< 10) { index in

                            HStack {

                                Text("Cell")
                                    .foregroundColor(.green)
                            }
                        }
                    }
                }

                Text("\(self.magnification.description)")
            }.gesture(magnificationGesture)
        }
    }
}


#if DEBUG
struct TimelineView_Previews: PreviewProvider {

    static var previews: some View {

        TimelineView()
    }
}
#endif
´´´

1 个答案:

答案 0 :(得分:0)

我更新到了Xcode 11 beta 5和macOS 10.15 beta 5,它现在似乎可以工作了。