简体   繁体   English

快速按钮调整动画大小

[英]Swift button resizing animation

I'm trying to animate button resizing, but all I get is instant already resized view. 我正在尝试为按钮调整大小设置动画,但是我得到的只是即时的已调整大小的视图。 What am i doing wrong? 我究竟做错了什么?

ps sorry for my bad english PS对不起我的英语不好

swift 5 迅捷5

 UIView.animate(withDuration: 10) {
            self.button.frame.size = CGSize(width: 195, height: 195)
            self.button.frame.size.width += 100
            self.button.frame.size.height -= 100
            self.button.center.y += 200
        }

first three lines inside curly brackets don't work as i expect, but the last one change the position of button as it has to 大括号内的前三行不符合我的预期,但是最后一行更改了按钮的位置,因为它必须

Thanks to everyone who tried to help me, after some researches I decided to use 感谢所有尝试帮助我的人,经过一些研究后,我决定使用

self.button.transform = CGAffineTransform(scaleX: 0.5, y: 0.5)

CGAffineTransform, instead of changing bounds or frames. CGAffineTransform,而不是更改范围或框架。 Now everything works fine 现在一切正常

You don't perform any arithmetics inside UIView.animate , you just set the final values of the constants that you want animated: 您无需在UIView.animate执行任何算术运算,只需设置要设置动画的常量的最终值即可:

UIView.animate(withDuration: 10) {
    self.button.frame.size.width = 10 // The new width of self.button
}

Same concept applies for any frame/width/height constants or even completely new frames. 相同的概念适用于任何帧/宽度/高度常数,甚至全新的帧。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM