我想使我的自定义线性图表可缩放(?)。经过研究,我使用pinch来缩放(swiftUI中的MagnificationGesture )来制作它。现在我的图表可以缩小或放大。但当我缩小它时,它覆盖了整个场景,这是我永远不想要的。我希望我的图表只在图表框架(我的意思是有限的屏幕区域)中缩小。我该如何解决这个问题?
@State变量比例: CGFloat = 1.0
let frame = CGSize(width: 350, height: 500)
public init(data: [Int], style: ChartStyle = Styles.lineChartStyleOne ){
self.style = style
}
var body: some View {
ZStack(alignment: .center){
VStack(alignment: .leading){
Spacer()
GeometryReader{ geometry in
Line(data: self.data, frame: .constant(geometry.frame(in: .local)), touchLocation: self.$touchLocation, showIndicator: self.$showIndicatorDot)
.offset(x: 15,y:0)
Legend(data: self.data, frame: .constant(geometry.frame(in: .local)), hideHorizontalLines: .constant(false))
RangeLineView(data: self.data, frame: .constant(geometry.frame(in: .local)))
RangeView(data: self.data, frame: .constant(geometry.frame(in: .local)))
}
.frame(width: frame.width, height: frame.height)
.scaleEffect(scale)
.gesture(MagnificationGesture()
.onChanged { value in
self.scale = value.magnitude
}
)
.offset(x: 0, y: 0)
}.frame(width: self.style.chartFormSize.width, height: self.style.chartFormSize.height)
}
}

发布于 2019-10-25 05:44:19
弄清楚我自己的想法...
.clipped(Rectangle())
这很简单,但它可以做到这一点。
https://stackoverflow.com/questions/58511763
复制相似问题