iOS跑马灯动画研究

方法1:

用这种方法退出后台再回来会消失.

 DLog(@"开始动画");
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:3.0f];
    [UIView setAnimationCurve:UIViewAnimationCurveLinear];
    [UIView setAnimationDelegate:self];
    [UIView setAnimationRepeatAutoreverses:NO];
    [UIView setAnimationRepeatCount:0];
    CGRect frame1 = a.frame;
    frame1.origin.x = -a.width - 10;
    _name.frame = frame1;
    [UIView commitAnimations];
    DLog(@"结束动画");

方法2:

- (void)paomaLabel{
    [UIView transitionWithView:self duration:3 options:UIViewAnimationOptionCurveLinear animations:^{
        CGRect frame1 = _name.frame;
        frame1.origin.x = CGRectGetWidth(_portrait.frame)+4 -_name.width - 15;
        _name.frame = frame1;
    } completion:^(BOOL finished) {
        CGRect frame = _name.frame;
        frame.origin.x = CGRectGetWidth(_portrait.frame)+4 + _name.width;
        _name.frame = frame;
        [self paomaXunHuan];
    }];
}

- (void)paomaXunHuan{
    if (!self.isOpen) {//关了
        return;
    }
    [UIView transitionWithView:self duration:6 options:UIViewAnimationOptionCurveLinear animations:^{
        CGRect frame = _name.frame;
        frame.origin.x = CGRectGetWidth(_portrait.frame)+4 - _name.width - 15;
        _name.frame = frame;
    } completion:^(BOOL finished) {
        CGRect frame = _name.frame;
        frame.origin.x = CGRectGetWidth(_portrait.frame)+4 + _name.width;
        _name.frame = frame;
        
        [self paomaXunHuan];
    }];
    
}
最后编辑于
©著作权归作者所有,转载或内容合作请联系作者
平台声明:文章内容(如有图片或视频亦包括在内)由作者上传并发布,文章内容仅代表作者本人观点,简书系信息发布平台,仅提供信息存储服务。

推荐阅读更多精彩内容