0

我试图使视图看起来几乎像 appStore 中的信息视图,在视图的前半部分显示文本,在后半部分显示图像。我尝试在另一个滚动视图中使用滚动视图。第一个视图(包含上半部分的文本视图和下半部分的滚动视图)滚动良好,但底部的滚动视图(包含多个图像视图)不滚动。

任何想法如何使第二个滚动视图滚动?

scrollView 是包含 textview 和 scrollview 的视图。
imageScrollView 是带有图像视图的视图。

[scrollView setContentSize:CGSizeMake(320, 585)];
[imageScrollView setContentSize:CGSizeMake(1520, 400)];
4

2 回答 2

1

我最近自己弄清楚了,但忘了发布答案。问题是我将 .xib 中滚动视图的大小设置为与代码中相同的大小。当我将其更改为 320,416 和 320,400 时,我能够使用 setContentSize 滚动它们。然后在 imageScrollView 中,我沿 x 轴添加图像(第一个图像位于 0,第二个图像宽度为 + 一个小空间,依此类推)。希望这可以帮助某人。

于 2011-07-28T09:08:01.673 回答
0

这是来自文档目录的滚动视图显示图像的代码 ByType .png 用户从 Iphone 照片库中分割的图像

- (void)viewDidLoad {
int scrollviewwidh = 120;

self.view.backgroundColor = [UIColor darkTextColor];

hiImage = [[UIImageView alloc]initWithFrame:CGRectMake(10, 10, 300, 240)];  
hiImage.backgroundColor = [UIColor blackColor];




hiImage.userInteractionEnabled = YES;

[hiImage.layer setBorderColor:[UIColor blackColor].CGColor];
[hiImage.layer setBorderWidth:2.01f];
[self.view addSubview:hiImage];
[hiImage release];
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(0, 260, 320, 110)];
[self.view addSubview:scroll];
scroll.showsHorizontalScrollIndicator = NO;
scroll.pagingEnabled=YES;
scroll.delegate=self;
scroll.contentSize=CGSizeMake(scrollviewwidh,80);
scroll.showsVerticalScrollIndicator =YES;
scroll.backgroundColor = [UIColor darkTextColor];


}

-(void) viewWillAppear:(BOOL)animated{
self.fileManager = [NSFileManager defaultManager];
NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory , NSUserDomainMask, YES);
self.documentsDir = [paths objectAtIndex:0];
NSLog(@"the ----------- %@",documentsDir);

for (UIButton * img in self.scroll.subviews) {
    [img removeFromSuperview];
    img = nil;
}
int xoffcet = 0;
int col = 0;
int scrollviewwidh = 120;

for (NSString* fileName in [self.fileManager contentsOfDirectoryAtPath: self.documentsDir error:nil]){
    if ( [fileName rangeOfString:@".png"].location != NSNotFound  ) {

        NSLog(@"add %@", fileName);
        UIImage* img = [UIImage imageWithContentsOfFile:
                        [self.documentsDir stringByAppendingPathComponent:fileName]
                        ];

        imgView = [[UIButton alloc] init];
        [imgView setImage:img forState:UIControlStateNormal];




        [imgView addTarget:self action:@selector(imageViewClicked:) forControlEvents:UIControlEventTouchUpInside];
        [imgView.layer setBorderColor:[UIColor lightGrayColor].CGColor];
        [imgView.layer setBorderWidth:1.0f];
        imgView.bounds = CGRectMake(10,10, 50, 50);
        imgView.frame = CGRectMake(5+xoffcet, 0, 160, 110);





        scroll.contentSize =CGSizeMake(scrollviewwidh+xoffcet,110);
        [scroll addSubview:imgView];
        [imgView release];
        xoffcet +=170;

    }

    if (col++>1) {
        //row++;
        col = 0;
    }
}




    self.title = @"saved Photo";
//  [scroll release];
[super viewDidLoad];
//  scroll.pagingEnabled = YES;

self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc]initWithBarButtonSystemItem:
                                         UIBarButtonSystemItemCancel 
                                                                                     target:self 
                                                                                     action:@selector(photogallary:)];



}

-(IBAction)imageViewClicked:(UIButton *)sender{


for (NSString* fileName in [self.fileManager contentsOfDirectoryAtPath: self.documentsDir error:nil]){
    if ( [fileName rangeOfString:@".png"].location != NSNotFound  ) {

        NSLog(@"add %@", fileName);
        UIImage* img = [UIImage imageWithContentsOfFile:
                        [self.documentsDir stringByAppendingPathComponent:fileName]];


        hiImage.image = img;
    }
}
}

所有最好的我希望它有用谢谢如果那是代码帮助请提供您的反馈

于 2012-01-04T06:43:12.337 回答