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

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

问题描述

我目前正在使用一个自定义视图控制器容器的应用程序。多个视图在屏幕上在同一时间,当一个人被窃听,所选择的视图控制器动画到全屏。在此过程中,所选择的视图控制器子视图很好地扩展(帧,字体大小等)虽然,UILabel的字体属性不能设置动画导致的问题。我曾尝试多种解决方案,但所有平掉闹心。

我已经试过的解决方案是:


  1. 取大图的截图和动画的变化(类似于Flipboard的如何做)

  2. 使用transform属性动画

  3. 放大了一个UIScrollView,并提请全屏时放大它。

  4. 设置adjustsFontSizeToFitWidth为YES并设置fontSize的前动画

一个已经最好的解决方案,到目前为止,但我并不感到满意。

我在寻找其他的建议,如果任何人有任何或一个UILabel顶替了流畅的动画使用[UIView的动画..]。

下面是一个很好的例子,它类似于什么,我想我的UILabel做到:
<一href=\"http://www.cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html\">http://www.cocoawithlove.com/2010/09/zoomingviewcontroller-to-animate-uiview.html

编辑:这code工作

  //装载视图self.label = [[的UILabel的alloc]初始化];
self.label.text = @TEXT;
self.label.font = [UIFont boldSystemFontOfSize:20.0];
self.label.backgroundColor =的UIColor clearColor][self.label sizeToFit][self.view addSubview:self.label];//动画self.label.font = [UIFont boldSystemFontOfSize:80.0];
self.label.transform = CGAffineTransformScale(self.label.transform,0.25,0.25);
[self.label sizeToFit][UIView的animateWithDuration:1.0动画:^ {
    self.label.transform = CGAffineTransformScale(self.label.transform,4.0,4.0);
    self.label.center = self.view.center;
}完成:^(BOOL完){    self.label.font = [UIFont boldSystemFontOfSize:80.0];
    self.label.transform = CGAffineTransformScale(self.label.transform,1.0,1.0);    [self.label sizeToFit]}];


解决方案

您可以像波纹管动画..改变你的的UILabel 的大小和字体这里我只是把如何改变的UILabel 与变换动画字体的例子。

  yourLabel.font = [UIFont boldSystemFontOfSize:35]; //设置要代替35字体大小
    yourLabel.transform = CGAffineTransformScale(yourLabel.transform,0.35,0.35);
    [UIView的animateWithDuration:1.0动画:^ {
        yourLabel.transform = CGAffineTransformScale(yourLabel.transform,5,5);
    }];

我希望这对您有所帮助。

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. Take a screenshot of the larger view and animating the change (similar to how Flipboard does)
  2. Animate by using the transform property
  3. Zooming out a UIScrollView and zooming it in when brought to full screen.
  4. Setting adjustsFontSizeToFitWidth to YES and setting the fontSize prior to animation

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

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

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

EDIT: This code works

// 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];

}];

解决方案

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);
    }];

I hope this helpful to you..

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

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