2017-05-02 41 views
0

嗨我已經在tableview單元格中添加了滾動視圖,但在iphone 5或5s上imageview的右側留有小空間。我添加了滾動視圖,而不是在scrollview中有另一個uiview並在uiview中有一個imageview。 enter image description hereScrollView在uitableview中以編程方式添加

UIScrollView * riderScroll = [[UIScrollView alloc] initWithFrame:frame]; 

    riderScroll.clipsToBounds = YES; 
    riderScroll.delegate = self; 
    riderScroll.pagingEnabled = YES; 
    [riderScroll setShowsHorizontalScrollIndicator:YES]; 
    [riderScroll setShowsVerticalScrollIndicator:NO]; 
      NSLog(@"%@",NSStringFromCGRect(cell.contentView.frame)); 
    NSLog(@"%@",NSStringFromCGRect(riderScroll.frame)); 
     NSLog(@"%@",NSStringFromCGRect(cell.outerView.frame)); 
    for (int i=0; i<obj.propertyImages.count; i++) { 

     float swipeWidth = screenWidth; 
     int x = i * swipeWidth; 


     UIView * insideView=[[UIView alloc]initWithFrame:CGRectMake(x, riderScroll.frame.origin.y, screenWidth, riderScroll.frame.size.height)]; 

     insideView.clipsToBounds = YES; 
      NSLog(@"%@",NSStringFromCGRect(insideView.frame)); 
     UIImageView * img = [[UIImageView alloc] initWithFrame:CGRectMake(0, insideView.frame.origin.y, insideView.frame.size.width, insideView.frame.size.height)]; 

     NSLog(@"%@",NSStringFromCGRect(img.frame)); 

     img.clipsToBounds = YES; 
     img.userInteractionEnabled = YES; 
     img.contentMode = UIViewContentModeScaleAspectFill; 
     UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] init]; 
     [tap addTarget:self action:@selector(tapOnImage:)]; 
     [img addGestureRecognizer:tap]; 
     img.tag = indexPath.row; 
     PropertyObject * imgObj = [obj.propertyImages objectAtIndex:i]; 
     NSString *imageUrl; 

     if (_isMyProperty || _isAllProperty) { 
      imageUrl = [NSString stringWithFormat:@"%@/%@",BASE_URL_IMAGE,imgObj.imgUrl]; 
     }else{ 
      imageUrl = [NSString stringWithFormat:@"%@/%@",BASE_URL_IMAGE,imgObj]; 

     } 

     imageUrl = [imageUrl stringByAddingPercentEscapesUsingEncoding:NSUTF8StringEncoding]; 

     [img setImageWithURL:[NSURL URLWithString:imageUrl] placeholderImage:[UIImage imageNamed:@""]completed:^(UIImage *image, NSError *error, SDImageCacheType cacheType, NSURL *imageURL) { 
      if (error) { 

      } 

     } usingActivityIndicatorStyle:UIActivityIndicatorViewStyleGray 

     ]; 


     [insideView addSubview:img]; 
     [riderScroll addSubview:insideView]; 
     [cell.outerView addSubview:riderScroll]; 
     NSLog(@"%@",NSStringFromCGRect(cell.outerView.frame)); 
     NSLog(@"%@",NSStringFromCGRect(riderScroll.frame)); 
     NSLog(@"%@",NSStringFromCGRect(insideView.frame)); 
     NSLog(@"%@",NSStringFromCGRect(img.frame)); 
     float maxContentSize = swipeWidth * obj.propertyImages.count; 
     riderScroll.contentSize = CGSizeMake(maxContentSize, cell.outerView.bounds.size.height); 
    } 

     } 
+0

變化的滾動視圖和包括滾動視圖內的意見的背景顏色,它會幫助你確定哪些元素在兩側顯示空格。 – NeverHopeless

+0

這是最外面的觀點。我通過改變顏色@NeverHopeless – salmancs43

+0

並從'最外部視圖'來檢查你的意思是'cell.outerView'? – NeverHopeless

回答

0

嘗試這樣的電池類:(未經測試給你一個想法)

-(void)layoutSubviews 
{ 
    [super layoutSubviews]; 
    [self.outerview setFrame:CGRectMake(0, 0, screenSize.width, self.outerview.frame.size .height)]; 
    ... 
    ... Similarly resize rider scrollview and its nested views 
    ... each one at a time and see when the required view 
    ... fits your need. 
    ... 
} 
相關問題