I rotated my view a few degrees with pan gesture recognizer and I checked out its frame. But in the normal state and in rotated state this view has the same frame, but on the screen I see rotated picture.
The question is: I want to know coordinates of the right low corner of this view after rotating. How to do it?
Hi @michael_nechaev,
There are two properties on a view, the one that you are looking at (frame) and the one you should look at (bounds).
Hope that helps,
Cheers,
Jayant
Unfortunately this values stay the same before and after rotating view.
It’s more core animation question, because in the affine transformations we change layer property of a view.
But its (layer) frame and bounds also remained the same
Hi @michael_nechaev,
how are you rotating the view? using the transform property of the view or … because if you are creating a CGAffineTransformation then bounds would give you the true bounds of the view.
VIEW.transform = VIEW.transform.rotated(by: absoluteAngle.radians)
print(VIEW.frame, VIEW.bounds)
this works for me, so if you can share some code on where it does not work for you, that could help to resolve your issue.
Here’s something for you to try, put this code in viewDidLoad()
label = UILabel(frame: CGRect(x: 100, y: 100, width: 100, height: 20))
label.text = "This is some text"
self.view.addSubview(label)
label.layer.borderWidth = 1
label.layer.borderColor = UIColor.black.cgColor
label.transform = label.transform.rotated(by: CGFloat((.pi * 45) / 180))
print(label.frame, label.bounds)
You should be able to see the label and the bounding box of the label.
cheers,
Jayant
No, I use CABasicAnimation property and call this function every time when I recognized rotation gesture
func rotate(to: CGFloat, duration: Double = 0, view: UIView) {
rotateAnimation.fromValue = to //- 26
rotateAnimation.toValue = to //- 26
rotateAnimation.duration = duration
rotateAnimation.repeatCount = 0
rotateAnimation.isRemovedOnCompletion = false
rotateAnimation.fillMode = kCAFillModeForwards
rotateAnimation.timingFunction = CAMediaTimingFunction(name: kCAMediaTimingFunctionLinear)
view.layer.add(rotateAnimation, forKey: "transform.rotation.z")
}
If your animation is using the same value for fromValue and toValue your animation won’t do anything…
This topic was automatically closed after 166 days. New replies are no longer allowed.