2015-11-12 91 views
3

我正在研究一個應用程序,其中包含一些顯示相冊列表的功能。我使用香草UITableView和香草UITableViewCell s。我正在使用Subtitle款式UITableViewCell並在cell.imageView.image上設置縮略圖。注意:這不是自定義單元格,而是內置單元格imageView。UITableViewCell圖像在選擇時會變大放大

問題是,當我點擊一個單元格時,imageView變得更大,這看起來很奇怪,因爲a)這不是直觀的行爲,b)它不再與其他每行相匹配。

的選擇之前,細胞的ImageView的框架是:

cell.imageView.frame: {{16, 1}, {84, 84}} 

選擇後,這些細胞的ImageView的框架是:

cell.imageView.frame: {{16, 0}, {88, 87.5}} 

我沒有參與任何代碼,這是一個香草UITableViewCell。

enter image description here

我有一個唯一的代碼與ImageView的相互作用是我用來獲取照片資產和更新單元格的PhotoKit代碼:

PHImageRequestOptions *options = [[PHImageRequestOptions alloc] init]; 
options.resizeMode = PHImageRequestOptionsResizeModeExact; 

[self.imageManager requestImageForAsset:asset 
       targetSize:AssetGridThumbnailSize 
       contentMode:PHImageContentModeAspectFill 
        options:options 
       resultHandler:^(UIImage *result, NSDictionary *info) { 

        // Only update the thumbnail if the cell tag hasn't changed. 
        // Otherwise, the cell has been re-used. 
        if (cell.tag == currentTag) { 
         cell.imageView.contentMode = UIViewContentModeScaleAspectFill; 
         cell.imageView.image = result; 
        } 

       }]; 

這究竟是爲什麼?我怎樣才能阻止它?

+0

我認爲你的tableView的'heightForRowAtIndex:'方法返回的值比單元格的高度要小。要測試它是否正常工作,請從此方法返回一些重要的大值。 – Shamsiddin

回答

-2

當你設置我找到UIImageView.ContentMode = UIViewContentModeScaleAspectFill

如果你請求一個網頁圖像,並下載具有完成和回調,該ImageView的將是改變它的框架

你可以試試這個方法

[img setClipsToBounds:YES]; 
+0

圖像沒有顯示更多,因此不需要滑動。它採用的是相同的圖像數據,不是從網絡上的PhotoKit中提取的,而是在更大的框架中顯示它。裁剪不會幫助,因爲框架已經變得更大。 –