自动分页滚动浏览



我有一个问题。我想在scrollview中向用户显示一些内容。我想从左到右快速自动滚动卷轴。我尝试使用ddautoscrollview(如果有人知道),但这对我不起作用。有人有一个解决方案以自动滚动uiscrollview水平吗?我已经为ScrollView设置了PageControl,因为它使用了分页。任何代码片段都很好。

我的代码(仅在scrollview):

.h

    @interface Interface1 : UIViewController {
    IBOutlet UIScrollView *scroller;

}

.m

- (void)viewDidLoad
{
    [scroller setScrollEnabled:YES];
    [scroller setContentSize:CGSizeMake(960, 230)];
        [super viewDidLoad];
}

我正在使用故事板和弧线。

谢谢

您无需为此使用任何额外的库。UISCROLLVIEW具有contentOffset属性,您可以将动画标志设置为是:

[myScrollView setContentOffset:CGPointMake(320, 0) animated:YES];

,或者您可以将其包装在Uiview动画中:

[UIView animateWithDuration:1.5f animations:^{
    [myScrollView setContentOffset:CGPointMake(320, 0) animated:NO];
}];

无论哪种方式,您都可能需要将滚动视图的内容大小设置为至少640宽,以便您实际上可以页面。

您正在寻找- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated。它可以让您在内容尺寸内给它一个一个平,并将其滚动到它。

http://developer.apple.com/library/ios/#documentation/uikit/reference/uiscrollview_class/reference/uiscrollview.html

我不知道您的确切速度但是您尝试过此方法吗?

- (void)setContentOffset:(CGPoint)contentOffset animated:(BOOL)animated
// In your case, e.g.:
[scroller setContentOffset:CGPointMake(640, 0) animated:YES]

最新更新