gpt4 book ai didi

ios - 旋转 MDRotatingPieChart 更改 x/y 位置而不是角度

转载 作者:搜寻专家 更新时间:2023-10-31 08:03:50 24 4
gpt4 key购买 nike

Screenshot of MDRotatingPieChart

我想在我的 iOS 应用程序中有一个旋转饼图。我发现 MDRotatingPieChart 控件似乎可以满足我的大部分需求。但是当我把它放到非 (0,0) 原点并开始拖动时,它也会改变饼图的 X 和 Y 位置。它不应该这样做。有人可以帮我吗?

这是看起来相关的代码

pieChart = MDRotatingPieChart(frame: CGRect(x: 30, y: 30, width: view.frame.width + 30 , height: view.frame.width + 30 ))

MDRotatingPieChart 中:

override func continueTracking(_ touch: UITouch, with event: UIEvent?) -> Bool {
hasBeenDraged = true
let currentPoint = touch.location(in: self)
let deltaX = currentPoint.x - pieChartCenter.x - 15
let deltaY = currentPoint.y - pieChartCenter.y - 15
let ang = atan2(deltaY,deltaX);
let angleDifference = delta - ang
self.transform = self.transform.rotated(by: -angleDifference)
let savedTransform = slicesArray[0].labelObj?.transform
let savedTransformCenter = labelCenter.transform
for slice in slicesArray {
if(slice.labelObj != nil) {
slice.labelObj?.transform = savedTransform!.rotated(by: angleDifference)
}
}
labelCenter.transform = savedTransformCenter.rotated(by: angleDifference)
return true;
}

最佳答案

首先,看起来您应该使用 MDRotatingPieChart-Example folder 中的 MDRotatingPieChart.swift,因为它更现代。它仍然包含您描述的错误,错误的来源似乎是原始开发人员不知道根据 UIView docframebounds 之间的区别:

The geometry of each view is defined by its frame and bounds properties. The frame property defines the origin and dimensions of the view in the coordinate system of its superview. The bounds property defines the internal dimensions of the view as it sees them and is used almost exclusively in custom drawing code.

因此,要解决此问题,您可以找到以下 line in createSlice

    mask.frame = self.frame

并将其替换为

    mask.frame = self.bounds

附言您的代码有一行

pieChart = MDRotatingPieChart(frame: CGRect(x: 30, y: 30, width: view.frame.width + 30 , height: view.frame.width + 30 ))

这很可疑。您几乎不希望子级的 widthheight 大于相应父级的尺寸。你可能想要

pieChart = MDRotatingPieChart(frame: CGRect(x: 30, y: 30,
width: view.frame.width - 30 , height: view.frame.width - 30 ))

甚至(如果您希望 X 和 Y 的边距对称)

pieChart = MDRotatingPieChart(frame: CGRect(x: 30, y: 30, 
width: view.frame.width - 2*30 , height: view.frame.width - 2*30 ))

相反。

关于ios - 旋转 MDRotatingPieChart 更改 x/y 位置而不是角度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48867035/

24 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com