我在UIScrollView中顯示大量圖像。在UIScrollview中佈置圖像
我也對視圖,其在按下時將擴大視圖,如圖所示的按鈕:
- (IBAction) expandButtonTouched {
NSLog(@"Expand Button Touched");
CGRect frame = CGRectMake(0, 50, 320, 410); // New scrollview location
CGRect scrollviewFrame = CGRectMake(0, 30, 320, 380);
[UIView beginAnimations:@"MoveAndStrech" context:nil];
[UIView setAnimationDuration:1];
[UIView setAnimationBeginsFromCurrentState:YES];
self.frame = frame;
scrollView.frame = scrollviewFrame;
[self layoutScrollImages];
[UIView commitAnimations];
}
我的佈局圖像的方法被定義爲這樣:
- (void)layoutScrollImages
{
UIImageView *view = nil;
NSArray *subviews = [scrollView subviews];
// reposition all image subviews in a horizontal serial fashion
CGFloat curXLoc = 0;
for (view in subviews)
{
if ([view isKindOfClass:[UIImageView class]] && view.tag > 0)
{
CGRect frame = view.frame;
frame.origin = CGPointMake(curXLoc, 0);
view.frame = frame;
curXLoc += (kScrollObjWidth);
}
}
// set the content size so it can be scrollable
[scrollView setContentSize:CGSizeMake((kNumImages * kScrollObjWidth), [scrollView bounds].size.height)];
}
問題是,在調整滾動視圖的大小後,其內容不會重新排序。它仍然只顯示圖像,在這裏我想它顯示爲這樣的單排(基於每第9張圖片):
1 2 3 | 10 11 12 | 19 20 21
4 5 6 | 13 14 15 | 22 23 24
7 8 9 | 16 17 18 | 25 26 27 (and so on)
你也可以失去UIImageView *聲明以及(UIImageView *視圖在子視圖中){....... – Matt 2011-05-27 23:28:20
@Matt UIScrollView中的滾動條在[UIScrollView子視圖]。 – TheBlack 2011-05-27 23:52:08