ModalViewController中的UIImageView是忽略ContentMode - iPhone

时间:2012-04-25 16:25:42

标签: iphone objective-c uiimageview xib contentmode

我正在呈现一个模态视图,其中UIImageView设置为内容模式填充比例(通过xib)。我在模态视图类中使用父类的缩略图设置UIImage:

NSURL * finishedMovie = [self applicationDocumentsDirectory:@"FinishedVideo.mov"];
MPMoviePlayerController *player = [[MPMoviePlayerController alloc] initWithContentURL:finishedMovie];
UIImage *thumbnail = [player thumbnailImageAtTime:1.0 timeOption:MPMovieTimeOptionNearestKeyFrame];

previewScreen = [[PreviewScreenViewController alloc]initWithNibName:@"PreviewScreenViewController" bundle:nil];
previewScreen.thumbnailImage = thumbnail;
[self presentModalViewController:previewScreen animated:YES];

然后在模态视图类中:

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view from its nib.
previewImageBox.image = thumbnailImage;

}

问题在于,当视图出现时,它似乎忽略了在xib中设置的内容模式,只是以完整大小插入图像。

这似乎是一个错误,因为当我返回到此视图时,图像正确地适合UIImage视图。

有人可以帮忙吗?

感谢。

2 个答案:

答案 0 :(得分:1)

好的解决了!如果您在代码中手动创建UIImageView,它似乎可以工作。

// Do any additional setup after loading the view from its nib.
//Work around to solve bug in UIToolkit where aspect ratio is ignored when view loads.
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(13, 87, 294, 164)];
//Set the image to our thumbnail.
[self.view addSubview:imageView];

答案 1 :(得分:0)

您很可能将clipsToBounds属性设置为NO。这将阻止UIImageView剪切其rect之外的内容。您可以设置borderColor图层的UIImageView,看看是否确实发生了这种情况。