动画 UILabel 字体大小更改 [英] Animating UILabel Font Size Change

查看:55
本文介绍了动画 UILabel 字体大小更改的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我目前正在制作一个使用自定义视图控制器容器的应用程序.多个视图同时出现在屏幕上,当点击其中一个时,选定的视图控制器将动画显示为全屏.这样做时,选定的视图控制器子视图也会缩放(框架、字体大小等).不过,UILabel 的字体属性不可设置动画,从而导致问题.我尝试了多种解决方案,但结果都很糟糕.

I am currently making an application that uses a custom View Controller container. Multiple views are on the screen at one time and when one is tapped, the selected view controller animates to full screen. In doing so, the selected view controllers subviews scale as well (frame, font size, etc.) Though, UILabel's font property is not animatable leading to issues. I have tried multiple solutions but all flat out suck.

我尝试过的解决方案是:

The solutions I have tried are:

  1. 截取较大视图的屏幕截图并为更改设置动画(类似于 Flipboard 的做法)
  2. 使用transform属性制作动画
  3. 缩小 UIScrollView 并在全屏时将其放大.
  4. 将FontSizeToFitWidth设置为YES并在动画之前设置fontSize

到目前为止,一个是最好的解决方案,但我对此并不满意.

One has been the best solution so far but I am not satisfied with it.

如果有人有任何使用 [UIView animate..] 平滑动画的 UILabel 替代品,我正在寻找其他建议.

I'm looking for other suggestions if anyone has any or a UILabel substitue that animates smoothly using [UIView animate..].

这是一个很好的例子,类似于我希望 UILabel 做的事情:http://www.cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html

Here is a good example that is similar to what I would like my UILabel to do: http://www.cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html

此代码有效

// Load View

self.label = [[UILabel alloc] init];
self.label.text = @"TEXT";
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor = [UIColor clearColor];

[self.label sizeToFit];

[self.view addSubview:self.label];

// Animation

self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform, .25, .25);
[self.label sizeToFit];

[UIView animateWithDuration:1.0 animations:^{
    self.label.transform = CGAffineTransformScale(self.label.transform, 4.0, 4.0);
    self.label.center = self.view.center;
} completion:^(BOOL finished) {

    self.label.font = [UIFont boldSystemFontOfSize:80.0]; 
    self.label.transform = CGAffineTransformScale(self.label.transform, 1.0, 1.0);

    [self.label sizeToFit];

}];

推荐答案

您可以使用如下动画更改 UILabel 的大小和字体...UILabel 的字体和变换动画 ..

You can change the size and font of your UILabel with animation like bellow .. here I just put the example of how to change the font of UILabel with transform Animation ..

    yourLabel.font = [UIFont boldSystemFontOfSize:35]; // set font size which you want instead of 35
    yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 0.35, 0.35); 
    [UIView animateWithDuration:1.0 animations:^{
        yourLabel.transform = CGAffineTransformScale(yourLabel.transform, 5, 5);
    }];

这篇关于动画 UILabel 字体大小更改的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆