TTFortuneWheel-iOS
TTFortuneWheel-iOS copied to clipboard
drawAdditionalGraphics draw icon in wrong slice.
@EfraimB : I did implement drawAdditionalGraphics as below:
public func drawAdditionalGraphics(in context: CGContext, circularSegmentHeight: CGFloat, radius: CGFloat, sliceDegree: CGFloat) {
let iconSize = CGSize(width: 32, height: 32)
let iconPadding: CGFloat = 50
let icon = UIImage // my icon
let centerOffset = CGPoint(x: -(radius - iconPadding) , y: -iconSize.height/2)
let additionalGraphicRect = CGRect(x: centerOffset.x, y: centerOffset.y, width: iconSize.width, height: iconSize.height)
let additionalGraphicPath = UIBezierPath(rect: additionalGraphicRect)
context.saveGState()
additionalGraphicPath.addClip()
context.scaleBy(x: 1, y: -1)
context.draw(icon.cgImage!, in: CGRect(x: additionalGraphicRect.minX, y: -additionalGraphicRect.minY, width: iconSize.width, height: iconSize.height), byTiling: true)
context.restoreGState()
}
Result:
The issue is my icon is showing in wrong slice. Could you please help me to fix it. Thank you
hi. did you manage to solve it?
Hey, There is an issue in this file FortuneWheelLayer, you can update your code with my solution and solve this issue.
Provided by library
//// Aditional graphics drwings
parent.slices.enumerated().forEach { (index,element) in
self.drawAdditionalGraphics(in: context, rotation: rotation, for: element)
let previousSlice:FortuneWheelSliceProtocol = parent.slices[safe:(index - 1)] ?? element
rotation += degree(of:previousSlice)
}
Edited Solution
//// Aditional graphics drwings
parent.slices.enumerated().forEach { (index,element) in
self.drawAdditionalGraphics(in: context, rotation: rotation, for: parent.slices[safe:(index - 1)] ?? element)
let previousSlice:FortuneWheelSliceProtocol = parent.slices[safe:(index - 1)] ?? element
rotation += degree(of:previousSlice)
}
Can you please make a PR with this fix? Thank you!