Category: Swift

Getting the rotation angle after CABasicAnimation?

Getting the rotation angle after CABasicAnimation?

I had a view that I rotate a lot, often more than 360 degrees (spins around a few times). Each time it stops, I wanted to determine the resulting “visual” angle. How does one go about doing that? rotateView is a configured CABasicAnimation:

Once done, I dispatch after the randomSpeed duration so I know …

Swift 3: Distance between two CGPoints

Swift 3: Distance between two CGPoints

Here it is in Swift 3, it’s a little different. I tried to use hypotf but it didn’t like CGFloat subtraction.

 

Protocol/delegates in Swift 3.0

Protocol/delegates in Swift 3.0

I declare this day a fine day having discovered non-Objective-C protocols! No more @objc protocol usage. Now it’s as simple as something like this:

And then in implementation

This is a really simple example, but it works and seems cleaner to me in Swift.