gpt4 book ai didi

ios - 使用动画问题缩小按钮的宽度

转载 作者:搜寻专家 更新时间:2023-10-31 22:58:34 27 4
gpt4 key购买 nike

我想在我的项目中复制这个动画

enter image description here

所以我尝试的是:

  1. 转换比例 X ..但问题是它也会缩小按钮的标题。

    self.transform = CGAffineTransform.identity
    UIView.animate(withDuration: duration, delay: delayTime,
    usingSpringWithDamping: 0.7,
    initialSpringVelocity: 0.7,
    options: [.curveEaseIn],
    animations: {
    self.transform = CGAffineTransform(scaleX: 0.5, y: 1.0)
    }, completion: nil)

    这就是它给出的(按钮的标题也缩小了)

    enter image description here

  2. CASpringAnimation的使用

    let shrinkAnim = CASpringAnimation(keyPath: "bounds.size.width")
    shrinkAnim.damping = 0.7
    shrinkAnim.initialVelocity = 0.7
    shrinkAnim.fromValue = frame.width
    shrinkAnim.toValue = width
    shrinkAnim.dura[![enter image description here][3]][3]tion = duration
    shrinkAnim.timingFunction = getTimingFunction(curve: curve)
    shrinkAnim.fillMode = kCAFillModeForwards
    shrinkAnim.isRemovedOnCompletion = false
    layer.add(shrinkAnim, forKey: shrinkAnim.keyPath)

    所以它可以改变标题的宽度和位置 enter image description here

所以我的问题是出了什么问题或者我需要添加什么来复制第一张图片?

My constraints for button is pinned to left, right and bottom edges and fix height. and more thing is I am making a class for this so I cant change constants because I have to use this in many screens .. so I want one stop solution.

最佳答案

不要使用 CGAffineTransform,而是采用 NSLayoutConstraint 属性 socket 作为 Button 的 width 并更改其 constant在动画 block /闭包中。

UIView.animate(withDuration: duration, delay: delayTime,
usingSpringWithDamping: 0.7,
initialSpringVelocity: 0.7,
options: [.curveEaseIn],
animations: {
self.buttonWidthConstraint.constant = desired_width_here
}, completion: nil)

关于ios - 使用动画问题缩小按钮的宽度,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/40779309/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com