Artun
Artun

Reputation: 303

Changing the anchor point of a button and then rotating the button by it's anchor

I'm trying to rotate my button by it's anchor point which is meant to be it's frame's right bottom corner. The rotation that I want is 60 degrees to the right.

So basically I want a button which rotates 60 degrees to right by it's new anchor point which is button frame's right bottom instead of it's center.

Outlet name of my button is: LoginScreenSelectionButton

So the code that I use is

 override func viewDidLoad() {
    super.viewDidLoad()

    let anchorPoint = CGPoint(x: LoginScreenSelectionButton.frame.width, y: LoginScreenSelectionButton.frame.height)
    LoginScreenSelectionButton.layer.anchorPoint = anchorPoint // setting new anchor
    LoginScreenSelectionButton.transform = CGAffineTransform(rotationAngle: CGFloat(60 * Double.pi/180))

}

When I use this code my button just disappears. I suppose that it rotates with a weird anchor point. Am I setting the anchor points wrong or rotation code is wrong?

I am adding the desired pre-rotation and post-rotation positions as well.

Initial position angle of the triangle Button

The exact rotation that I want to have after the rotation

Thank you.

Upvotes: 1

Views: 235

Answers (0)

Related Questions