From the course: iOS Development Tips

Unlock this course with a free trial

Join today to access over 23,200 courses taught by industry experts.

Sliders as knobs

Sliders as knobs

- [Instructor] You've seen other apps rotate views, but you may have no idea how to do it yourself. Let me show you one way to rotate views. We'll make a simple knob control you might be able to use in your apps. Download the example file. On the storyboard, I added a UI image view of a knob and a label. In the view controller code I have over here, I set this up to use some touch methods for user interaction. You can check out my earlier tip on touch and the Apple pencil on how to use these methods. You do translations like rotations using the layer property of UIView. Now layer is a CA layer, and that has a property transform, and the touchesMoved method inside those braces for if let equals touches.first, I'm going to get that property. I'm going to assign that property by doing knob.layer.transform equals. There's a couple of ways of doing this transform, but I prefer using the 3D ones over others, so I'm going to add this method CATransform3DMakeRotation, and there it is right…

Contents