2013-01-12 198 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

回答

相關問題