3

我希望滚动视图(或 textView)自动滚动,就像显示电影的演职员表时一样。我尝试了一些方法,但没有一个成功,我似乎找不到足够的答案,任何帮助将不胜感激!

提前致谢!

4

3 回答 3

4

此代码将UIScrollView在 10 秒内滚动您的 100pt:

self.scrollView.scrollEnabled = NO;

CGFloat scrollHeight = 100;
[UIView animateWithDuration:10
                      delay:0
                    options:UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction
                 animations:^{
                     self.scrollView.contentOffset = CGPointMake(0, scrollHeight);
                 }
                 completion:nil];
于 2012-09-25T13:52:04.850 回答
1

试试这个。

[your table-name scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:pageval inSection:0] atScrollPosition:0 animated:YES];

indexPathForRow您可以传递您的行号并将其递增到行尾。

我认为这会奏效。

希望这会有所帮助

**

当你使用 textview 时,你可以试试这个

**

count=txtvw.frame.size.height; //integer counter initialized as textview's height

//call "scrolltextview" method at regular time interval. (here it is calling method in 0.3 second timespan)
self.timer = [NSTimer scheduledTimerWithTimeInterval:.3f
                                                  target:self
                                                selector:@selector(scrolltextview)
                                                userInfo:nil
                                                 repeats:YES];



 -(void)scrolltextview
{


     //iterate "count" every time the method is called by the lineheight of textview's font.
        count=count+ txtvw.font.lineHeight;


    if(count<=txtvw.text.length)
    {
    NSRange range = NSMakeRange(count - 1, 1);

        [txtvw scrollRangeToVisible:range]; // scroll with range
    }
    else {
        [timer invalidate]; // if count match with the condition than invalidate the timer so method not called now.
    }

}



我将它与NSTimer对象一起使用。希望这会有所帮助。

于 2012-09-20T03:57:39.700 回答
1
class AutoScrollView: UIScrollView {
    var timer: Timer?
    override func didMoveToSuperview() {
        super.didMoveToSuperview()
        timer?.invalidate()
        timer = Timer.scheduledTimer(timeInterval: 1.0 / 30.0, target: self, selector: #selector(timerAction), userInfo: nil, repeats: true)
    }
    @objc func timerAction() {
        contentOffset.y = contentOffset.y + 1
        if contentOffset.y >= contentSize.height - bounds.height {
            contentOffset.y = 0
        }
    }
}

上面将自动滚动滚动视图并在它到达结束时循环它。

于 2018-08-11T18:38:14.907 回答