Getting the true rotation of a UIView layer
Getting the true rotation of a UIView layer
- Subject: Getting the true rotation of a UIView layer
- From: "Eric E. Dolecki" <email@hidden>
- Date: Wed, 15 Mar 2017 03:13:35 +0000
I have a view that I am rotating a lot, often more than 360 degrees (spins
around a few times). Each time it stops, I want to determine the resulting
"visual" angle. How do I go about doing that?
rotateView is a configured CABasicAnimation:
*let rotateView = CABasicAnimation()*
*let randonAngle = arc4random_uniform(361) + 1440*
*rotateView.fromValue = 0*
*rotateView.toValue = Float(randonAngle) * Float(M_PI) /
Float(randomBetweenNumbers(firstNum: 90.0, secondNum: 180.0))//180.0*
*let randomSpeed = randomBetweenNumbers(firstNum: 1.5, secondNum: 2.1)*
*rotateView.duration = CFTimeInterval(randomSpeed)*
*rotateView.repeatCount = 0*
*rotateView.isRemovedOnCompletion = false*
*rotateView.fillMode = kCAFillModeForwards*
*rotateView.timingFunction = CAMediaTimingFunction(name:
kCAMediaTimingFunctionEaseOut)*
*innerRing.layer.add(rotateView, forKey: "transform.rotation.z")*
Once done (I dispatch after the randomSpeed duration), I'd like to
determine the angle it's currently at.
*let transform:CATransform3D = innerRing.layer.transform*
*let angle: CGFloat = atan2(transform.m12, transform.m11);*
*print(angle)*
Always prints 0.0
Am I missing something obvious? I almost thought about using hitTest but
there must be a way to get this after each spin?
Thank you,
Eric
_______________________________________________
Cocoa-dev mailing list (email@hidden)
Please do not post admin requests or moderator comments to the list.
Contact the moderators at cocoa-dev-admins(at)lists.apple.com
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden