- Java 双重比较
- java - 比较器与 Apache BeanComparator
- Objective-C 完成 block 导致额外的方法调用?
- database - RESTful URI 是否应该公开数据库主键?
我想在我的 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
doc 的 frame
和 bounds
之间的区别:
The geometry of each view is defined by its
frame
andbounds
properties. Theframe
property defines the origin and dimensions of the view in the coordinate system of its superview. Thebounds
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 ))
这很可疑。您几乎不希望子级的 width
或 height
大于相应父级的尺寸。你可能想要
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/
我在我的应用程序中使用 MDRotatingPieChart 并创建了一个饼图。我需要饼图切片之间的空间。有人可以帮我解决这个问题吗? 最佳答案 在piechartdataset上设置splicesp
我想在我的 iOS 应用程序中有一个旋转饼图。我发现 MDRotatingPieChart 控件似乎可以满足我的大部分需求。但是当我把它放到非 (0,0) 原点并开始拖动时,它也会改变饼图的 X 和
我是一名优秀的程序员,十分优秀!