我尝试将该属性设置为原子属性,但它似乎无论如何都不起作用。这是代码。它移动显示正在播放的歌曲名称的标签。有时它开始抖动,就好像标签应该同时出现在两个地方一样。有什么线索吗?一些锁定属性可能...
- (void)animateSongLabel
{
if (!self.player.rate) {
[UIView animateWithDuration:.5 animations:^{
self.songLabel.left = 25.f;
}];
return;
}
[UIView animateWithDuration:.25 delay:0. options:UIViewAnimationOptionCurveLinear animations:^{
self.songLabel.left -= 15.f;
} completion:^(BOOL finished) {
if (self.songLabel.right < -10.f) {
self.songLabel.left = 320.f;
}
[self animateSongLabel];
}];
}
最佳答案
制作仅坐在那里并横向滚动的文本的最简单方法是显示动画 UIImage 或动画 UIImageView - 尤其是前者,因为它永远具有动画效果,这可能就是您想要的。通过每次稍微偏移地绘制文本,在代码中生成连续的 UIImage 对象,并将它们交给 animatedImageWithImages:duration:
。现在,无论您在哪里显示该图像,它都将具有动画效果。
这里有一些示例代码可以帮助您入门(进行调整以准确获得您想要的效果):
NSString* s = @"Mister Dobbalena, Mister Bob Dobbalena";
NSMutableArray* marr = [NSMutableArray array];
UIFont* f = [UIFont fontWithName:@"Helvetica" size:12];
float w = [s sizeWithFont:f].width;
for (int offset = 0; offset < w; offset++) {
UIGraphicsBeginImageContextWithOptions(self.iv.frame.size, NO, 0);
[s drawAtPoint:CGPointMake(10-offset,20) withFont:f];
[marr addObject: UIGraphicsGetImageFromCurrentImageContext()];
UIGraphicsEndImageContext();
}
UIImage* im = [UIImage animatedImageWithImages:marr duration:20];
self.iv.image = im;
关于ios - UIViewanimationWithDuration递归导致抖动,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14308409/