我想要一個滾動視圖,每次在滾動視圖上顯示5個縮略圖。 基本上它是一行一行,每行都有5個縮略圖。 您將手指向右滑動,然後顯示下一組5個縮略圖。UIScrollView和圖像縮略圖
我需要做什麼?我們是否需要滾動視圖才能這樣做?我該如何開始?
我想要一個滾動視圖,每次在滾動視圖上顯示5個縮略圖。 基本上它是一行一行,每行都有5個縮略圖。 您將手指向右滑動,然後顯示下一組5個縮略圖。UIScrollView和圖像縮略圖
我需要做什麼?我們是否需要滾動視圖才能這樣做?我該如何開始?
在你的UIView將包含在-viewDidLoad您的UIScrollView,地方(像)驗證碼:
UIScreen *screen = [UIScreen mainScreen];
pageWidth = screen.bounds.size.height;
pageHeight = screen.bounds.size.width;
scrollView = [[UIScrollView alloc] initWithFrame:CGRectMake(0.0f, 0.0f, pageWidth, pageHeight)];
[scrollView setAutoresizingMask:UIViewAutoresizingNone];
[scrollView setContentSize:CGSizeMake(numPages * pageWidth, pageHeight)];
[scrollView setContentOffset:CGPointMake(pageWidth, 0)];
[scrollView setPagingEnabled:YES];
[scrollView setDelaysContentTouches:YES];
[scrollView setDelegate:self];
[scrollView setClearsContextBeforeDrawing:NO];
[scrollView setOpaque:YES];
[self.view insertSubview:scrollView atIndex:0];
[scrollView release];
// iterate through your thumbnails - which are UIViews
thumbnailViews = [NSMutableArray array];
[thumbnailViews retain];
NSUInteger pageCounter = 0;
for (...)
{
ThumbnailView *thumbnailView = [[ThumbnailView alloc] initWithFrame:CGRectMake(pageCounter*pageWidth, 0, pageWidth, pageHeight)];
[thumbnailView setMultipleTouchEnabled:YES];
[thumbnailView setViewController:self]; // this may be necessary to push/pop on navigation controller stack.
[thumbnailView restoreState];
[scrollView thumbnailView];
[thumbnailViews thumbnailView];
++pageCounter;
}
在我的情況下,頁寬,pageHeight,thumbnailViews和滾動視圖是我的UIView子類的所有實例變量。
我只是看着這裏,因爲我自己學習UIScrollView
。我開始嘗試讓westsider的代碼工作,但我注意到它實際上是一團糟。它應該在執行<UIScrollViewDelegate>
協議的UIViewController
中,而像[scrollView thumbnailView];
這樣的內容是沒有意義的,因爲這裏的thumbnailView
是一個方法名稱。我相信http://www.codeproject.com/Articles/46556/How-To-Use-UIScrollView-in-Your-iPhone-App.aspx更連貫。
要回答這個問題,我想你想以標準的方式來創建一個UIScrollView
- 如在鏈接,您要創建的UIView
一個子類叫,說,UIView5
有5 UIImageViews
。然後,您不需要在UIScrollView
(如[scrollView addSubview:standardUIView];
)中添加正常的UIView
,而是添加UIView5
對象。
你能解釋一下UIScreen的含義嗎? – aherlambang 2010-11-04 23:10:03
在我的情況下,我希望每個'縮略圖'填充可用的屏幕空間。如果你對較小的區域感到滿意,那麼你可以定義pageWidth/pageHeight。從:「UIScreen對象包含設備整個屏幕的邊界矩形。設置您的應用程序的用戶界面,您應該使用此對象的屬性來爲應用程序的窗口獲取推薦的框架矩形。「 –
westsider
2010-11-04 23:13:31
所以你說這個滾動視圖會填滿整個視圖? – aherlambang 2010-11-05 02:38:05