【发布时间】:2011-05-27 23:07:53
【问题描述】:
我在 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* 声明以及只拥有 for (UIImageView* view in subviews){.......
-
@Matt Scrollbars in UIScrollView 也在 [UIScrollView subviews] 中。
标签: iphone objective-c layout uiscrollview