iphone - 动画 UILabel 字体大小变化

标签 iphone ios animation uilabel

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

我尝试过的解决方案是:

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

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

我正在寻找其他建议,如果有人有任何 UILabel 替代品可以使用 [UIView animate..] 流畅地制作动画。

这是一个很好的例子,它类似于我希望我的 UILabel 做的事情: 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 的大小和字体 .. 这里我只是举了一个例子,说明如何使用 transform Animation 更改 UILabel 的字体..

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

关于iphone - 动画 UILabel 字体大小变化,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14494566/

相关文章:

ios - 词典词典

iOS动画翻书封面和轻松起来

ios - 在没有 Storyboard的情况下使用 BWWalkthrough 库,Walkthrough Custom

swift - 将贝塞尔曲线路径置于 UIview 的中心?

iphone - 在应用程序中购买 Urban Airship 帮助

iphone - Cocos2d-iphone 对 iPhone 4 高分辨率的支持

iphone - 舍入到 "beautiful"值

ios - 核心图像自动调整在 CPU 上渲染速度太慢

swift - View 没有动画

ios - 如何使用 SwiftUI 为一系列图像制作动画?