我有一个具有全屏 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
旋转设备时,我应该使用更好的方法来重新配置滚动视图和图像吗?