现在的位置: 首页 > 综合 > 正文

iphone UILable 跑马灯效果 / 滚动

2018年07月30日 ⁄ 综合 ⁄ 共 696字 ⁄ 字号 评论关闭

继承UILable 重载drawRect,修改如下,即可

// Drawing code

- (void)drawRect:(CGRect)rect
{
    [super drawRect:rect];
    float w = self.frame.size.width;
    
//    if (motionWidth >= w) {
//        return;
//    }
    
    CGRect frame = self.frame;
    frame.origin.x = 320;
    self.frame = frame;
    
    [UIView beginAnimations:@"textAnimation" context:NULL];
    
   // [UIView setAnimationDuration:8.0f*(w<320?320:w) /320.0];
    
    [UIView setAnimationDuration:8.0f * (w < 320 ? 320:w ) / 320.0];
    
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatAutoreverses:NO];//是否能反转
    [UIView setAnimationRepeatCount:LONG_MAX];//重复次数
    
    frame = self.frame;
    frame.origin.x = -w;
    self.frame = frame;
    [UIView commitAnimations];
}

抱歉!评论已关闭.