TTFortuneWheel-iOS icon indicating copy to clipboard operation
TTFortuneWheel-iOS copied to clipboard

drawAdditionalGraphics draw icon in wrong slice.

Open tuanph3012 opened this issue 6 years ago • 3 comments

@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:

Icon is drawing in wrong slice

The issue is my icon is showing in wrong slice. Could you please help me to fix it. Thank you

tuanph3012 avatar Jul 08 '19 09:07 tuanph3012

hi. did you manage to solve it?

ain1712 avatar Dec 31 '19 01:12 ain1712

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)
        }

HimanshuParashar avatar Aug 19 '20 08:08 HimanshuParashar

Can you please make a PR with this fix? Thank you!

EfraimB avatar Nov 11 '22 10:11 EfraimB