2014-09-26 65 views
0

我有一個滾動視圖作爲橫幅,包含15個圖像視圖作爲子視圖(水平滾動)。我想補充的子視圖是這樣的:滾動視圖上的子視圖的不必要的反彈

for (int i = 0; i < featuredImages.count; i++) { 

    CGRect frame; 
    frame.origin.x = self.scrollViewFeaturedImages.frame.size.width * i; 
    frame.origin.y = 0; 
    frame.size = self.scrollViewFeaturedImages.frame.size; 

    UIImageView *subview = [[UIImageView alloc] init]; 
    subview.frame = frame; 
    [self.scrollViewFeaturedImages addSubview:subview]; 
} 

,並據此設置contentSize:

self.scrollViewFeaturedImages.contentSize = CGSizeMake(self.scrollViewFeaturedImages.frame.size.width * featuredImages.count, self.scrollViewFeaturedImages.frame.size.height); 

self.scrollViewFeaturedImages.contentInset = UIEdgeInsetsZero; 

然而,鑑於出現時,第一形象似乎是有點過。

space between image frame and scroll frame

當我滾動(水平)到下一個圖像,所述間隙消失,並且當我滾動回第一圖像,該幀被已經校正。

我也禁用了BOUNCE,但我可以垂直拖動圖像。

enter image description here

我也試過這樣:

self.automaticallyAdjustsScrollViewInsets = NO; 

沒有成功。

發生了什麼事?

+0

如何將圖像設置爲「UIImageViews」? – Suryakant 2014-09-26 08:05:32

+0

@SuryakantSharma [subview setImageWithURL:[NSURL URLWithString:featured.background_url]]; (setImageWithURL來自名爲SDWebImage的庫;延遲加載) subview.contentMode = UIViewContentModeScaleToFill; – hardluckbaby 2014-09-26 08:08:07

+0

我可以假設,圖像是從URL正確加載的? – Suryakant 2014-09-26 08:38:56

回答

1

經過兩週困惑後,我終於通過在viewDidAppear中添加這些行來修復此問題。

self.scrollViewFeaturedImages.contentInset = UIEdgeInsetsZero; 
self.scrollViewFeaturedImages.scrollIndicatorInsets = UIEdgeInsetsZero; 
0

您是否嘗試將UIImageView的屬性contentMode更改爲UIViewContentModeScaleToFill

+0

是的,我做過。這是整個imageView框架在視圖出現時關閉。 – hardluckbaby 2014-09-26 05:51:01

相關問題