美文网首页
iOS 消息滚动、循环播出

iOS 消息滚动、循环播出

作者: focusHYD | 来源:发表于2019-04-26 16:26 被阅读0次

直接上代码连接
https://github.com/HeYunDong/notiveScrollview

// 开启定时器

- (void)startTimer {
    if (!_timer) {
        _timer = [NSTimer timerWithTimeInterval:_timeInterval target:self selector:@selector(timerMethod) userInfo:nil repeats:YES];
        [[NSRunLoop currentRunLoop] addTimer:_timer forMode:NSRunLoopCommonModes];
    }
}

/// 定时器方法

- (void)timerMethod {
    _count++;
    if (_count == _contents.count) {
        _count = 0;
    }

    /// 两次动画实现类似UIScrollView的滚动效果,控制坐标和隐藏状态
    [UIView animateWithDuration:_scrollTimeInterval animations:^{
        _scrollLbl.frame = CGRectMake(0, -Height, Width, Height);
    } completion:^(BOOL finished) {
        _scrollLbl.hidden = YES;
        _scrollLbl.frame = CGRectMake(0, Height, Width, Height);
        _scrollLbl.hidden = NO;
        [UIView animateWithDuration:_scrollTimeInterval animations:^{
            _scrollLbl.text = [self getCurrentContent];
            _scrollLbl.frame = CGRectMake(0, 0, Width, Height);
        } completion:^(BOOL finished) {
            
        }];
    }];
}

相关文章

网友评论

      本文标题:iOS 消息滚动、循环播出

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