自动滚动滚动视图

我有个问题。 我想在UIScrollView显示用户的一些内容。 我想从底部到顶部快速autoscroll UIScrollView (如在苹果商店的iPad )。 我试图使用DDAutoscrollview (如果有人知道),但它不适合我。 有没有人为我autoscroll UIScrollView的解决scheme? 任何代码片段都会很好。

。H

 @interface Interface1 : UIViewController { IBOutlet UIScrollView *scroller; IBOutlet UILabel *warnung; } @property (nonatomic, retain) IBOutlet UIScrollView* scrollView; 

.M

 - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView.bounds.size.height); [self.scrollView setContentOffset:bottomOffset animated:NO]; CGPoint newOffset = self.scrollView.contentOffset; newOffset.y = 0; [self.scrollView setContentOffset:newOffset animated:YES]; } - (void)viewDidLoad { [scroller setScrollEnabled:YES]; [scroller setContentSize:CGSizeMake(320, 420)]; [super viewDidLoad]; } 

谢谢。


>为TOBI给予的赞助者提供帮助!


只需使用setContentOffset:animated:

 UIScrollView *scrollView = ...; CGPoint newOffset = scrollView.contentOffset; newOffset.y = 0; [scrollView setContentOffset:newOffset animated:YES]; 

编辑:

要像使用某种开始animation一样使用它,你可以在scrollView的视图控制器中做到这一点:

 - (void)viewDidLoad { [super viewDidLoad]; // ... CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView.bounds.size.height); [self.scrollView setContentOffset:bottomOffset animated:NO]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; CGPoint newOffset = self.scrollView.contentOffset; newOffset.y = 0; [self.scrollView setContentOffset:newOffset animated:YES]; } 

编辑2/3:

为了使滚动发生得更慢,使用这个:

 - (void)viewDidLoad { [super viewDidLoad]; // ... CGPoint bottomOffset = CGPointMake(self.scrollView.contentOffset.x, self.scrollView.contentSize.height - self.scrollView.bounds.size.height); [self.scrollView setContentOffset:bottomOffset animated:NO]; } - (void)viewDidAppear:(BOOL)animated { [super viewDidAppear:animated]; float scrollDuration = 4.0; [UIView animateWithDuration:scrollDuration animations:^{ self.scrollView.contentOffset = CGPointMake(self.scrollView.contentOffset.x, 0); }]; }