zrz*_*zka 21
我假设您知道如何在启用分页的情况下将图像添加到UIScrollView.我还假设您想要查看全屏照片,但在滚动时,您希望它们之间存在差距.如果是,这是可能的解决方案之一......
...如果您不想进行缩放,只需全屏,分页,滚动间隙,这是非常快速的解决方案.
这只是基础数学..
您将UIImageView添加为子视图,并计算您想知道子视图大小和scrollView的contentSize的空间.
编辑:
这基本上建立了一个画廊
-(void)photosGallery
{
UIScrollView* scrollView = [[UIScrollView alloc] initWithFrame:(CGRect){.origin.x = 0.0f, .origin.y = 0.0f, .size.width = 320.0f, .size.height = 416.0f}];
scrollView.contentSize = (CGSize){.width = view.frame.size.width, .height = 372.0f};
scrollView.backgroundColor = [UIColor whiteColor];
scrollView.showsVerticalScrollIndicator = NO;
scrollView.showsHorizontalScrollIndicator = NO;
/// Build gallery
CGSize thumbSize = (CGSize){.width = 75.0f, .height = 75.0f};
const CGFloat xSpace = (scrollView.frame.size.width - (thumbSize.width * kPictsPerRow)) / (kPictsPerRow + 1); // kPictsPerRow = Number of pictures in a row
const CGFloat xInc = thumbSize.width + xSpace;
const CGFloat yInc = thumbSize.height + 15.0f;
CGFloat x = xSpace, y = 10.0f;
for (NSUInteger i = kMaxPictures; i--;)
{
UIImageView* pv = [[UIImageView alloc] initWithFrame:(CGRect){.origin.x = x, .origin.y = y, .size = thumbSize}];
[scrollView addSubview:pv];
[pv release];
x += xInc;
const NSUInteger eor = i % kPictsPerRow;
if (!eor)
y += yInc, x = xSpace;
}
[scrollView release];
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
7161 次 |
| 最近记录: |