是的,我正在尝试获得带有文本的标签(显然已经完成),它在屏幕上滚动.
输入标签的文本由UITextField和UIButton完成.这个更新很好.
但是我试图让UILabel根据文本输入的大小调整大小,以便整个屏幕滚动整个文本.
这是我目前滚动标签的代码:
[lblMessage setText: txtEnter.text];
CABasicAnimation *scrollText;
scrollText=[CABasicAnimation animationWithKeyPath:@"position.x"];
scrollText.duration = 3.0;
scrollText.repeatCount = 10000;
scrollText.autoreverses = NO;
scrollText.fromValue = [NSNumber numberWithFloat:500];
scrollText.toValue = [NSNumber numberWithFloat:-120.0];
[[lblMessage layer] addAnimation:scrollText forKey:@"scrollTextKey"];
Run Code Online (Sandbox Code Playgroud)
问题是,有时会开始在屏幕中间滚动,有时会在完全消失之前消失.
由于标签是一个尺寸,它也削减文本..我不知道如何改变这一点.
提前致谢.
大教堂
我相信类似于这个问题的解决方案的东西适用于这种情况.
您可以将UILabel嵌入到UIScrollView中,并将UIScrollView设置为您希望一次显示在屏幕上的标签的最大大小.UIScrollView需要使用showsHorizontalScrollIndicator和showsVerticalScrollIndicator属性关闭其滚动指示器.在更改文本时,您可以执行以下操作:
[lblMessage setText: txtEnter.text];
[lblMessage sizeToFit];
scrollView.contentSize = lblMessage.frame.size;
Run Code Online (Sandbox Code Playgroud)
然后是上面链接的问题中描述的平移动画代码,其中框架将被平移为UILabel的最右侧.这将导致文本在标签上以恒定速率滚动.如果您希望标签回滚到开头,可以在动画块的开头使用UIView setAnimationRepeatAutoreverses:和setAnimationRepeatCount:方法.
| 归档时间: |
|
| 查看次数: |
8008 次 |
| 最近记录: |