2011-04-21 222 views
0

我試圖使視圖看起來幾乎像appStore中的信息視圖,上半年的視圖和圖像的下半年的文本。我試圖在另一個滾動視圖中使用滾動視圖。第一個視圖(包含上半部分的textview和下半部分的scrollview)滾動很好,但底部的滾動視圖(包含幾個圖像視圖)不滾動。Xcode:滾動視圖與滾動視圖中的圖像

任何想法如何使第二個滾動視圖滾動?

scrollView是包含textview和scrollview的視圖。
imageScrollView是帶有圖像瀏覽的視圖。

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

回答

1

我最近搞清楚了自己,但忘了發佈答案。問題在於我將.xib中的滾動視圖的大小設置爲與代碼中的大小相同。當我將其更改爲320,416和320,400時,我可以使用setContentSize來滾動它們。在imageScrollView中,我沿x軸添加圖像(第一個圖像爲0,第二個圖像寬度爲+小空間等等)。希望這可以幫助某人。

0

下面是從文檔滾動視圖顯示圖像的代碼誰從iPhone照片庫seved用戶目錄byType的巴紐圖片

- (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; 
    } 
} 
} 

一切順利,我希望它有用謝謝如果這就是代碼的幫助,請給你的反饋