2012-11-07 57 views
0

我有问题。我想在滚动视图中显示用户的一些内容。我想从左到右快速自动滚动滚动视图。我试图使用DDAutoscrollview(如果有人知道),但它不适合我。有没有人给我一个解决方案来自动滚动Uiscrollview?我已经为scrollview设置了一个pagecontrol,因为它使用了分页。任何代码片段都会很好。自动分页滚动视图

我的代码(只是滚动视图):

.H

@interface Interface1 : UIViewController { 

    IBOutlet UIScrollView *scroller; 


} 

.M

- (void)viewDidLoad 
{ 

    [scroller setScrollEnabled:YES]; 
    [scroller setContentSize:CGSizeMake(960, 230)]; 

     [super viewDidLoad]; 
} 

我用故事板和ARC。

感谢

回答

2

您不需要为此使用任何额外的库。 UIScrollView中有一个contentOffset属性上,您可以简单地设置动画标志是:

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

或者你可以在一个UIView动画包装它:

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

无论哪种方式,你可能会想将滚动视图的contentSize设置为至少640宽,以便您可以实际页面。

+0

我只是想将scrollview页面向右移动,如果用户加载视图 – MasterRazer

+0

我应该在哪里使用这段代码? – MasterRazer

+0

我该如何重复这一步骤? – MasterRazer

0

我不知道如何快速准确,但你有没有尝试过这种方法吗?

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