ios - 动画垂直滚动文本

标签 ios xcode uiviewcontroller uilabel

我正在一个应用程序中实现一个关于 View Controller ,当点击一个按钮时它会显示模态。

在 View Controller 上,我有一个 UILabel 和一些显示在其中的文本。我想为文本设置动画,使其自动淡入或向上滚动显示制作该应用程序的团队成员的姓名 - 就像在电影结尾滚动的演职员表。

有人对 UILabel 中的文本进行类似的滚动吗?

最佳答案

UIScrollView 应该可以解决问题。让它无限循环的一种非常快速的方法是在顶部和底部有一个与 ScrollView 大小相同的空白区域。 (还有其他解决方案,like this 或 WWDC 代码(搜索“street scroller”here ...但这些对于“关于” View 来说可能有点多)。

但是如果内容的每一端都有空白,你可以像这样循环:

- (void)loopCredits {

    CGRect frame = self.creditsScrollView.frame;
    CGPoint bottomOffset = CGPointMake(0, self.creditsScrollView.contentSize.height-frame.size.height);

    [UIView animateWithDuration:10.0 animations:^{
        self.creditsScrollView.contentOffset = bottomOffset;
    } completion:^(BOOL finished) {
        // non animated scroll back, then run this method again with a perform
        // so we don't wind up the stack
        self.creditsScrollView.contentOffset = CGPointZero;
        [self performSelector:@selector(loopCredits) withObject:nil afterDelay:0];
    }];

可以使用 mask 图像轻松完成淡入淡出,或者为了获得更逼真的外观,您可以根据标签相对于标签在 scrollView 边界内的 Y 偏移的位置来计算 alpha 级别。

关于ios - 动画垂直滚动文本,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17126709/

相关文章:

ios - 如何使用 swift 创建自定义弹出 View ?

ios - UIBarButtonItemStyleBordered 已弃用;我该怎么办呢?

ios - 防止faSTLane扫描隐藏模拟器

Swift - 如何从 NavigationController 中删除 View Controller ?

ios - 来自 Xib 文件错误的 Swift init ViewController

php - iOS - 没有推送通知的常见原因是什么

ios - Swift - 以模态方式打开 WebView 链接

ios - 使用容器 ViewController,如何在 subview Controller 之间添加交互式动画?

ios - View Controller 无法找到带有标识符的 Segue

ios - 无法显示我的 iOS VoIP 应用程序的 onComingCall ViewController