0

我正在尝试制作水平滚动

这是我的代码

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)];

下面是图片

在此处输入图像描述

在此处输入图像描述

您可以看到我为特定区域定义了滚动视图,但图像分布在整个屏幕上。如何限制滚动视图的滚动宽度。

4

2 回答 2

1

如果我正确理解您的问题(这很困难),请尝试

self.handScrollView.clipsToBounds = YES;
于 2013-08-09T10:13:57.767 回答
0

您是否尝试在 xib 文件上设置 autoresizingMask?

如果不尝试如下图所示:

在此处输入图像描述

于 2013-08-09T10:45:01.447 回答