我有一個應用程序,它具有全屏UIScrollView,其中有七個圖像。圖像也是全屏顯示,滾動視圖設置爲啓用分頁。自動旋轉設備時UIScrollView中的圖形故障
我有或者創建或移動圖像視圖的方法:
-(void)rebuildImageView{
// set up images
float screenW = self.view.bounds.size.width;
float screenH = self.view.bounds.size.height;
int numImgs = self.soundNames.count;
self.mainScrollView.contentSize = CGSizeMake(screenW * numImgs, screenH);
for(int i=0; i<numImgs; i++){
UIImageView* imageView = (UIImageView*)[self.mainScrollView viewWithTag:i+100];
if(imageView == nil){
imageView = [[UIImageView alloc] init];
imageView.tag = i+100;
[self.mainScrollView addSubview:imageView];
imageView.image = [UIImage imageNamed:[NSString stringWithFormat:@"image%d.jpg",i]];
imageView.contentMode = UIViewContentModeScaleAspectFill;
imageView.clipsToBounds = YES;
[imageView release];
}
imageView.frame = CGRectMake(i * screenW, 0, screenW, screenH);
}
// scroll to the current one
[self.mainScrollView scrollRectToVisible:CGRectMake(self.currentSound*screenW, 0, screenW, screenH) animated:YES];
}
我也有這個視圖控制器上:
-(void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
[UIView animateWithDuration:duration animations:^{
[self rebuildImageView];
}];
}
當我自轉而圖像0此代碼工作正常正在顯示,但是當我在圖像7上時,您可以在旋轉時簡要查看圖像6的大部分內容。該視頻顯示發生的事情:
http://www.youtube.com/watch?v=1O3jOcTgVP8
是否有更好的方法,旋轉設備時,我應該使用重新配置滾動視圖和圖像?
我也嘗試改變調用'scrollRectToVisible:'有'動畫:否'。沒有改變它。 – Tim