【问题标题】:Rotate button on center axis中心轴上的旋转按钮
【发布时间】:2021-10-08 00:53:42
【问题描述】:

我编写了以下代码来旋转标签栏按钮。但看起来它会旋转左下轴上的按钮,导致按钮略微向右移动。

如何让它绕中心轴旋转?

private func rotateCenterButton(reverse: Bool = false)
{
    if let item = self.tabBarController?.tabBar.items?[2],
       let view = item.value(forKey: "view") as? UIView
    {
        UIView.animate(withDuration: 0.25, animations: {
            view.transform = CGAffineTransform(rotationAngle: reverse ? CGFloat(0) : CGFloat.pi / 4)
        })
    }
}

感谢您的帮助

【问题讨论】:

    标签: swift uitabbarcontroller


    【解决方案1】:

    解决了这样的 mt 问题:

    private func rotateCenterButton(reverse: Bool = false)
    {
        if let item = self.tabBarController?.tabBar.items?[2],
           let view = item.value(forKey: "view") as? UIView
        {
            let bt = view.subviews.first
            bt!.contentMode = .center
            UIView.animate(withDuration: 0.25, animations:{
                bt!.transform = reverse ? .identity : CGAffineTransform(rotationAngle: .pi/4)
            })
        }
    }
    

    【讨论】:

      猜你喜欢
      • 2019-04-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2013-08-06
      • 2013-02-12
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多