正如在代碼
[picker dismissViewControllerAnimated:YES completion:^{
[arr_images insertObject:chosenImage atIndex:0];
[self scrollImages_Setup2];
}];
[arr_images insertObject:chosenImage atIndex:0];這意味着您只需要在滾動視圖中顯示一個圖像。那麼爲什麼你需要一個循環:
-(void)scrollImages_Setup2
{
for (int k=0; k<arr_images.count; k++) {
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake((CGRectGetWidth(scl.frame) * k) + CGRectGetWidth(scl.frame), 0, CGRectGetWidth(scl.frame), CGRectGetHeight(scl.frame))];
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.image=[arr_images objectAtIndex:k] ;
[scl addSubview:imageView];
}
scl.contentSize = CGSizeMake((CGRectGetWidth(scl.frame) * arr_images.count)+CGRectGetWidth(scl.frame), CGRectGetHeight(scl.frame));
}
你恰到好處的代碼只是爲了顯示圖像。您不需要滾動視圖以僅顯示一個圖像。我想你不清楚你想要什麼。
您的問題是由於循環而覆蓋圖像。所以在顯示單個圖像時,請刪除循環。請刪除scrollview的contentSize,因爲image_array會增加,當你在數組中添加多個圖像時,size的寬度將會很大。所以刪除arr_images.count。
你是什麼意思圖像重疊時試圖刪除? –
你使用NSMutableArray嗎? – Misha
@ShamasS,圖片數據持久存在圖片視圖 – user2526811