您的位置:首页 > 编程语言 > PHP开发

TTPhotoViewController 在不同interfaceOrientation下的显示问题

2011-09-07 14:57 453 查看
最近在使用Three20库进行开发,并使用了TTPhotoViewController 来显示照片,不清楚大家是否遇到过我这样的问题:直接TTPhotoViewController ,使用在竖屏的时候,图片显示是错误了,此时图片上自动放大,且经常会显示到其他页的图片;而在横屏的情况下是正确的。

参考了网上一些解决方法:将TTPhotoView.m的- (void)setImage:(UIImage*)image函数中的UIViewContentModeScaleAspectFill改为UIViewContentModeScaleAspectFit,依照该方法修改后,此时发现竖屏是正确的,但是横屏确显示的是小图,无法满屏显示。

由此得出,在不同的interfaceOrientation下,需设置不同的contentmode。因此经过实验,修改代码如下:

TTPhotoViewController .m

增加函数:updatePhotoViewContentMode:(UIInterfaceOrientation)interfaceOrientation

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)updatePhotoViewContentMode:(UIInterfaceOrientation)interfaceOrientation
{
TTPhotoView* centerPhotoView = self.centerPhotoView;
UIViewContentMode currentContentMode;
if (UIInterfaceOrientationIsLandscape(interfaceOrientation)) {
currentContentMode = UIViewContentModeScaleAspectFill;
}
else{
currentContentMode = UIViewContentModeScaleAspectFit;
}
//先设置非当前view到contentMode,防止旋转时,会看到非centerPhotoview
for (TTPhotoView* photoView in _scrollView.visiblePages.objectEnumerator) {
if (centerPhotoView == photoView)
break;
photoView.contentMode = currentContentMode;
}
centerPhotoView.contentMode = currentContentMode;
}


修改代码:

///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration {
[super willAnimateRotationToInterfaceOrientation:toInterfaceOrientation duration:duration];
[self updateToolbarWithOrientation:toInterfaceOrientation];
[self updatePhotoViewContentMode:toInterfaceOrientation];
}


///////////////////////////////////////////////////////////////////////////////////////////////////
- (void)loadImages {
TTPhotoView* centerPhotoView = self.centerPhotoView;
for (TTPhotoView* photoView in _scrollView.visiblePages.objectEnumerator) {
if (photoView == centerPhotoView) {
[photoView loadPreview:NO];

} else {
[photoView loadPreview:YES];
}
//修改interfaceOrientation
if (UIInterfaceOrientationIsLandscape(self.interfaceOrientation)){
photoView.contentMode = UIViewContentModeScaleAspectFill;
}
else{
photoView.contentMode = UIViewContentModeScaleAspectFit;
}
}

if (_delayLoad) {
_delayLoad = NO;
[self startImageLoadTimer:kPhotoLoadLongDelay];

} else {
[centerPhotoView loadImage];
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: