Reputation: 3084
Example 1:
let halfPie = Double.pi / 2
var pieCount: Int = 0
let rotationNum = (pieCount % 4) + 1
let angle = halfPie * Double(rotationNum)
UIView.animate(withDuration: 1, animations: { [weak self] in
self?.containerView.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
}) { [weak self] _ in
self?.pieCount += 1
}
Example 2:
let halfPie = 1.5707963267949
var pieCount: Int = 1
let angle = halfPie * Double(pieCount)
UIView.animate(withDuration: 1, animations: { [weak self] in
self?.containerView.transform = CGAffineTransform(rotationAngle: CGFloat(angle))
}) { [weak self] _ in
self?.pieCount += 1
}
The difference between the two is that the second continues to increase, and the first keeps the number to max at PIE * 2. Is there any reason to impliment it one way over the other? They both seem to do the same thing. pieCount is initialized globally.
Upvotes: 0
Views: 51
Reputation: 13296
There is no difference.
If you animate to 180° or 540°, the animation will be the same since the view will do the least amount of movement to get to the correct position.
On a side note, you shouldn't be hardcoding halfPie
you should use Double.pi/2
Upvotes: 1