2012-06-29 54 views
0

我想導航到我的畫廊中左右滑動的上一張和下一張圖片,但之後我不想要上一個下一個按鈕。在搜索我碰到滑動手勢,是我必須使用或簡單的滾動視圖?任何人都可以提供想法如何做到這一點。有任何想法嗎?上一個下一個導航

+0

我剛剛發佈了一個答案(含代碼)在類似的問題 [這裏] [1] [1]:http://stackoverflow.com/questions/6244776/iphone-navigate-to-previous-next-viewcontroller/11617283#11617283 –

回答

1

其中一個UIScrollViewcontentSize水平展開就足夠了。

例如,假設你有4名UIImageView對象,他們是在imageViewArray

for (int i = 0; i < 4; i++) 
{ 
    UIImageView *imgView = [imageViewArray objectAtIndex:i]; 
    //one thing to note is while adding the image views, don't forget to change each views frame.origin.x property accordingly (in this case, each one will increase by the width of the view 
    //e.g. 
    imgView.frame = CGRectMake (self.view.frame.size.width * i, 0, self.view.frame.size.width, self.view.frame.size.height); 

    [yourScrollView addSubview:imgView]; 
} 


[yourScrollView setContentSize:CGSizeMake(self.view.frame.size.width * 4, self.view.frame.size.height)]; // 4 is the number that will expand the scrollview horizontally 
+0

編輯了一個錯誤,現在應該不需要投票了。 –

+0

那麼滾動會正常工作?我會嘗試一下,讓你知道..任何方式感謝您的幫助 – user1441511

+1

是的,它應該。而關於'pagingEnabled'屬性,它將使滾動僅停留在其中一個圖像上,否則滾動將停止在您停止滑動的點上。正如Apple所說的,如果此屬性的值爲YES,那麼當用戶滾動時,滾動視圖停止滾動視圖邊界的倍數。默認值是NO._ –

0

我想你應該使用scrollView並啓用分頁功能。我建議不要自己實施這個畫廊。爲此目的使用一些開源庫。查看three20庫。

http://three20.info/

0

我建議使用UIScrollViewpagingEnabled設置爲YES。有了這個,您可以使用UIScrollView作爲所有圖像/圖像瀏覽的包裝。

相關問題