我在UIView中有一个包含一些默认文本的UITextfield。我想要动画缩放这个textField (以及父UIView) %300,然后再降到100%。
我该怎么做呢?似乎我找到的每一件事都涉及到一个黑客图像捕获和一个CGAffineTransformMakeScale。
我已经花了很多时间来寻找它,它要么是困难和/或昂贵的,要么是完全琐碎的实现。如果是后者,我不会感到惊讶。:)
发布于 2015-02-25 20:12:01
您不必从视图中捕获图像,只需使用以下代码对标注进行缩放变换即可
[UIView beginAnimations:nil context:nil];
label.transform = CGAffineTransformMakeScale(3.0, 3.0);
[UIView commitAnimations];
但这种方法的唯一问题是文本可能看起来不清晰。
如果你想让UILabel
的伸缩性更清晰,我建议你试试核心文本框架。这肯定会帮助你实现你的目标。
可以在here上找到相同的教程。
发布于 2015-02-25 20:21:21
ios/documentation/CoreAnimation_guide
CAKeyframeAnimation *animation = [CAKeyframeAnimation animation];
animation.keyPath = @"position.x";
animation.values = @[ @0, @10, @-10, @10, @0 ];
animation.keyTimes = @[ @0, @(1 / 6.0), @(3 / 6.0), @(5 / 6.0), @1 ];
animation.duration = 0.4;
animation.additive = YES;
[form.layer addAnimation:animation forKey:@"shake"];
或
iOS - Animating text size change in UILabel or UITextView?
这可能会对您有所帮助:)
发布于 2018-06-05 06:11:37
在Swift 4.1中
对于FontSize,使用UIView.animate(withDuration:)
不起作用。使用CGAffineTransform
很难管理,而且必须应用于UILabel
或UITextField
,但正如接受的响应中所说的那样,结果并不明确。
这就是我正在使用的解决方案。
var fontSize: CGFloat = 12.0
Timer.scheduledTimer(withTimeInterval: 0.02, repeats: true) { (timer) in
self.font = UIFont(name: "Roboto-Regular", size: fontSize)
fontSize += 0.5 // Or 0.333 to allow for 3X resolution screens.
if fontSize > 17.0 {
timer.invalidate()
}
}
https://stackoverflow.com/questions/28718407
复制相似问题