[英]How to scroll to a certain point in a UIScrollView
下面我有一行代碼滾動到UIScrollView
的某個點。 但是一旦滾動它就不允許我向后滾動。
[scroller setContentOffset:CGPointMake(0,500) animated:NO];
任何幫助將不勝感激,謝謝。
我用這個。 該按鈕調用此方法。 應該運作良好。
- (void)downExecute:(id)sender {
NSLog(@"scroll down");
CGFloat currentOffset = _scrollView.contentOffset.y;
CGFloat newOffset;
newOffset = currentOffset + self.view.bounds.size.height;
[UIScrollView animateWithDuration:0.3 animations:^(void) {
[_scrollView setContentOffset:CGPointMake(0.0, newOffset)];
} completion:^(BOOL finished) {
}];
}
你嘗試使用UIScrollView方法scrollRectToVisible:這是一個例子
- (void)goToPage:(int)page animated:(BOOL)animated
{
CGRect frame;
frame.origin.x = self.scroller.frame.size.width * page;
frame.origin.y = 0;
frame.size = self.scroller.frame.size;
[self.scroller scrollRectToVisible:frame animated:animated];
// update the scroll view to the appropriate page
}
我有這種問題因為我從viewDidLayoutSubviews()調用了這個方法。 檢查你在哪里打電話。 當我將邏輯移動到viewDidAppear()時,一切都按預期工作。 希望它有所幫助,歡呼。
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.