Я бы хотел, чтобы моя пользовательская линейная диаграмма масштабировалась (?). после исследования я использовал Pinch для увеличения (MagnificationGesture в swiftUI), чтобы сделать это. Теперь мой график может уменьшаться или уменьшаться. Но когда я уменьшаю масштаб, он покрывает всю сцену, чего я никогда не хочу. Я хочу, чтобы мой график уменьшался только в рамке графика (я имею в виду ограниченную область экрана). Как я могу решить эту проблему?
@ State var scale: 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)
}
}
