0
アニメーションでボタンが大きくなったり小さくなったりします。ボタンと一緒にフォントを大きくしたり小さくしたりするにはどうすればいいですか?私のコードは以下の通りです。Swift 3ボタンでフォントをアニメーション化する方法
func animate() {
let originalFrame = self.playButton.frame
let originalBackgroundColor = self.playButton.backgroundColor
UIView.animateKeyframes(withDuration: 2, delay: 0, options: UIViewKeyframeAnimationOptions.calculationModeLinear, animations: {
// make the button grow and become dark gray
UIView.addKeyframe(withRelativeStartTime: 0.0, relativeDuration: 0.5) {
self.playButton.frame.size.height = self.playButton.frame.size.height * 1.2
self.playButton.frame.size.width = self.playButton.frame.size.width * 1.2
self.playButton.frame.origin.x = self.playButton.frame.origin.x - (self.playButton.frame.size.width/12)
self.playButton.frame.origin.y = self.playButton.frame.origin.y - (self.playButton.frame.size.height/12)
}
// restore the button to original size and color
UIView.addKeyframe(withRelativeStartTime: 0.5, relativeDuration: 0.5) {
self.playButton.frame = originalFrame
self.playButton.backgroundColor = originalBackgroundColor
}
}, completion: nil)
}
'originalFontSizeは=自己ましょう。 playButton?.font.pointSize':UIButton.fontはもう動作しません。 –
'UIButton'自体にはフォント属性はありませんが、' UIButton.titleLabel'は行います。 –
私は間違いを犯す、それは素晴らしい作品です。ありがとう! –