joshdhenry / SpinWheelControl

An inertial spinning wheel UI control that allows selection of an item. Cocoapod written in Swift.
BSD 3-Clause "New" or "Revised" License
73 stars 25 forks source link

Horizontal wedge content #6

Closed marcosgriselli closed 6 years ago

marcosgriselli commented 6 years ago

Re-edit as I realized the problem.

I want to display horizontal elements on the wedge rather than vertically. I added an UIImageView using a mask and following the SpinWheelWedgeLabel which works as expected but it rotates the image (the same way it rotates the label). This is what I'm trying to achieve.

horizontalelements

Should I be editing the transform or layer position? Or everything?

marcosgriselli commented 6 years ago

Update: I'm rotating the UIImage before adding it to the wedge and works perfectly for every case now.

I'm having issues finding the correct rotation for the label at each case. At the moment I got it to work with only a 4 wedge wheel with this transform:

public func configureWedgeLabel(index: UInt, width: CGFloat, position: CGPoint, radiansPerWedge: Radians) {
        frame = CGRect(x: 0, y: 0, width: width, height: 30)
        layer.anchorPoint = CGPoint(x: 0.5, y: 4.5)
        layer.position = position
        transform = CGAffineTransform(rotationAngle: radiansPerWedge * CGFloat(index + 1) + (radiansPerWedge / 2))
        text = "wedge #\(index)"
        setDefaultValues()
    }
joshdhenry commented 6 years ago

I haven’t yet attempted to add labels like that. I hope to try it this weekend and see if I can get something working.

marcosgriselli commented 6 years ago

Great, I'll be playing with it a little bit as well. Trying to add tap on wedge functionality. I'll send a PR if I get it correct.

joshdhenry commented 6 years ago

Haven't forgot about this. Trying to catch up and merge pull requests and answer questions for this repo but it is taking longer than I thought.

joshdhenry commented 6 years ago

Sorry for the delay, been busy! But this worked for me:

@objc public func configureWedgeLabel(index: UInt, width: CGFloat, position: CGPoint, radiansPerWedge: Radians) {

frame = CGRect(x: 0, y: 0, width: width, height: 30)

layer.anchorPoint = CGPoint(x: 0.5, y: 4.5)

layer.position = position

transform = CGAffineTransform(rotationAngle: radiansPerWedge * CGFloat(index) + (CGFloat.pi / 2) + (radiansPerWedge / 2))

text = "wedge #\(index)"

setDefaultValues()

}

Let me know if it works for you. I'd like to add it as a feature.

joshdhenry commented 6 years ago

In the newest version, 0.2.0, spin wheels can now be inited with the orientation property of type WedgeLabelOrientation. This allows us to give the wedge label different positions and orientations. Currently WedgeLabelOrientation can either be .inOut or .around.