美文网首页收藏ios
iOS跑马灯动画研究

iOS跑马灯动画研究

作者: 超_iOS | 来源:发表于2017-05-24 17:27 被阅读103次

    方法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];
        }];
        
    }
    

    相关文章

      网友评论

        本文标题:iOS跑马灯动画研究

        本文链接:https://www.haomeiwen.com/subject/mrlgnttx.html