使用NStimer移动Scrollview页面

时间:2014-04-02 11:19:01

标签: ios objective-c ios5 uiscrollview nstimer

我在UIScrollView有5个页面的示例代码。当S滚动UIScrollView页面更改时。并将pageControl放在示例代码中。但我想滚动UIScrollView而不滚动它。与NSTimer类似,它会自动滚动。

2 个答案:

答案 0 :(得分:1)

1-时间表NSTimer

// fire every second 
self.scrollTimer = [NSTimer scheduledTimerWithTimeInterval:1 target:self selector:@selector(timerFired) userInfo:nil repeats:YES];

2-火上滚动一页

- (void)timerFired
{
    CGFloat pageSize = scrollView.contentSize.width / scrollView.frame.size.width;
    // if this is the last page return
    if(scrollView.contentOffset.x >= scrollView.contentSize.width) {
        [scrollView setContentOffset:CGPointMake(0.0, scrollView.contentOffset.y) animated:YES];
    } else {
        [scrollView setContentOffset:CGPointMake(scrollView.contentOffset.x + pageSize, scrollView.contentOffset.y) animated:YES];
    }
}

答案 1 :(得分:0)

您必须使用scrollRectToVisible

[scrMain scrollRectToVisible:rect animated:YES];

关注此tutorial