更改按钮的锚点,然后通过其锚点旋转按钮

问题描述

我试图通过它的锚点旋转我的按钮,锚点是它的框架的右下角。我想要的旋转是向右 60 度。

所以基本上我想要一个按钮,它通过它的新锚点向右旋转 60 度,该锚点是按钮框架的右下角而不是中心。

我的按钮的出口名称是:LoginScreenSelectionButton

所以我使用的代码

 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))

}

当我使用此代码时,我的按钮消失了。我想它会随着一个奇怪的锚点旋转。是我设置的锚点错误还是旋转代码错误

我还添加了所需的旋转前和旋转后位置。

Initial position angle of the triangle Button

The exact rotation that I want to have after the rotation

谢谢。

解决方法

暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!

如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。

小编邮箱:dio#foxmail.com (将#修改为@)