我正在一个应用程序中实现一个关于 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/