2013-01-12 49 views
3

几个小时我一直试图弄清楚为什么UIScrollView不会显示来自NSMutableArray的图像。UIViewContentModeScaleAspectFit不适用于UIScrollView子视图UIImageView

我意识到uiimageview对象在UISCrollview内的子视图集合中,但不知何故UIViewContentModeScaleAspectFit被忽略了......我怎样才能适合于缩放呢?

please,any tips?

- (void)viewDidLoad 
{ 
    [super viewDidLoad]; 

    BookDalc* bookDalc = [[BookDalc alloc] init]; 

    NSMutableArray* books = [bookDalc FindByIconID:IconID]; 

    for(int i = 0;i<books.count;i++) 
    { 
     CGRect frame; 
     frame.origin.x = self.scrBook.frame.size.width * i; 
     frame.origin.y = 0; 
     frame.size = self.scrBook.frame.size; 

     UIImageView *subview = [[UIImageView alloc] initWithFrame:frame]; 
     subview.contentMode = UIViewContentModeScaleAspectFit; 

     BookEntity *currentModel = [books objectAtIndex:i]; 
     UIImage *currentImage = [currentModel TheImage]; 

     subview.image = currentImage; 
     [self.scrBook addSubview:subview]; 
    } 
    self.scrBook.contentSize 
    = CGSizeMake(self.scrBook.frame.size.width * books.count, self.scrBook.frame.size.height); 
} 
+0

只是一个快速的想法...你试过self.scrBook.bounds.width而不是self.scrBook.frame.size.width等....? – jhilgert00

+0

是的,我做过,同样的事情 – RollRoll

+0

很难从你的代码中知道。你有一个样本项目吗?你是否试图在视图上呈现1张图片,看看它是否正确显示? – Yariv

回答

相关问题