簡體   English   中英

自動分頁滾動視圖

[英]Automatic paging scrollview

我有個問題。 我想在滾動視圖中向用戶顯示一些內容。 我想從左到右快速自動滾動滾動視圖。 我試圖使用DDAutoscrollview(如果有人知道),但它對我不起作用。 有人幫我自動滾動Uiscrollview嗎? 我為scrollview設置了一個pagecontrol,因為它使用了分頁。 任何代碼片段都會很好。

我的代碼(Just of the Scrollview):

。H

    @interface Interface1 : UIViewController {

    IBOutlet UIScrollView *scroller;


}

.M

- (void)viewDidLoad
{

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

        [super viewDidLoad];
}

我正在使用Storyboards和ARC。

謝謝

您不需要為此使用任何額外的庫。 UIScrollView有一個contentOffset屬性,您可以在其上簡單地將動畫標志設置為YES:

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

或者你可以將它包裝在UIView動畫中:

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

無論哪種方式,您可能希望將滾動視圖的contentSize設置為至少640寬,以便您可以實際進行分頁。

你正在尋找- (void)scrollRectToVisible:(CGRect)rect animated:(BOOL)animated 它允許你在contentSize中給它一個rect,它會滾動到它。

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]

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM