【问题标题】:how to make effects on button in ios.On clicking on that button it should expand如何对ios中的按钮产生影响。单击该按钮时,它应该展开
【发布时间】:2020-06-29 15:04:19
【问题描述】:

我想在按钮上应用效果。如果单击该按钮,它应该会增加大小,其他应该保持原来的大小。在下图中,如果单击 jardin,它应该会展开。

【问题讨论】:

  • 你能告诉我们你已经尝试过什么吗?您可以为约束设置动画。
  • 这对于 Stack Overflow 来说太宽泛了。你需要开始工作。达到让所有工作没有按钮展开的地步,然后尝试调整约束或使用CGAffineTransformScale。如果遇到问题,请回来提出具体问题。
  • 我不知道该怎么做,所以我问@DennisJackman

标签: ios objective-c swift swift3 swift5


【解决方案1】:

这里是动画和转换按钮的代码。 它在你的方面完美运行

func changeButtons(selectedButton:UIButton)
{
    firstBtn.backgroundColor = .white
    firstBtn.setTitleColor(.black, for: .normal)
    animateButton(button: firstBtn, transformBy: .identity)

    secondBtn.backgroundColor = .white
    secondBtn.setTitleColor(.black, for: .normal)
    animateButton(button: secondBtn, transformBy: .identity)

    thirdBtn.backgroundColor = .white
    thirdBtn.setTitleColor(.black, for: .normal)
    animateButton(button: thirdBtn, transformBy: .identity)

    selectedButton.backgroundColor = .black
    selectedButton.setTitleColor(.white, for: .normal)
    animateButton(button: selectedButton, transformBy: CGAffineTransform(scaleX: 1.2, y: 1.2))
}
func animateButton(button : UIButton,transformBy:CGAffineTransform)
{
    UIView.animate(withDuration: 0.2) {
        button.transform = transformBy
        self.view.layoutIfNeeded()
    }
}
@IBAction func btnFirstPress(_ sender: UIButton)
{
    changeButtons(selectedButton: firstBtn)
}
@IBAction func btnSecondPress(_ sender: UIButton)
{
    changeButtons(selectedButton: secondBtn)
}
@IBAction func btnThirdPress(_ sender: UIButton)
{
    changeButtons(selectedButton: thirdBtn)
}

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 2011-02-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多