我正在尝试制作水平滚动
这是我的代码
int frameSize = 140;
for (int i = 0; i < self.handArray.count + 10 ; i++)
{
CGRect frame;
frame.origin.x = i * frameSize;
frame.origin.y = 0;
frame.size = CGSizeMake(130, 130);
UIView *view = [[UIView alloc] initWithFrame:frame];
view.backgroundColor = [UIColor whiteColor];
UIImage *image;
// if (i == 0)
image = [UIImage imageNamed:@"halo.png"];
//else
// image = [UIImage imageWithContentsOfFile:[self.handArray objectAtIndex:i]];
UIButton *btn = [UIButton buttonWithType:UIButtonTypeCustom];
[btn setImage:[UIImage imageNamed:@"cross_red.png"] forState:UIControlStateNormal];
btn.tag = i;
btn.frame = CGRectMake(102, 0, 29, 29);
[btn addTarget:self action:@selector(deleteHandBtnPressed:) forControlEvents:UIControlEventTouchUpInside];
UIImageView *imageView = [[UIImageView alloc] initWithImage:image];
imageView.frame = CGRectMake(10, 10, 120, 120);
[view addSubview:imageView];
if (i != 0)
[view addSubview:btn];
[self.handScrollView addSubview:view];
}
[self.handScrollView setContentSize:CGSizeMake(frameSize * (self.handArray.count + 10), self.handScrollView.frame.size.height)];
以下是图片
你可以看到我为特定区域定义了scrollView,但图像在整个屏幕上分布。如何限制滚动视图滚动宽度。
答案 0 :(得分:1)
如果我理解你的问题(很难),请尝试
self.handScrollView.clipsToBounds = YES;
答案 1 :(得分:0)
您是否尝试在xib文件上设置autoresizingMask?
如果没有尝试如下图所示: