【问题标题】:UIImageView in ModalViewController is Ignoring ContentMode - iPhoneModalViewController 中的 UIImageView 正在忽略 ContentMode - iPhone
【发布时间】:2012-04-25 16:25:42
【问题描述】:

我正在呈现一个模式视图,其中 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 视图。

谁能帮忙?

谢谢。

【问题讨论】:

  • 您是否尝试在 viewDidAppear 中设置图像?

标签: iphone objective-c uiimageview xib contentmode


【解决方案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];

【讨论】:

    【解决方案2】:

    您很可能将clipsToBounds 属性设置为NO。这将防止UIImageView 剪切其矩形之外的内容。你可以设置UIImageView层的borderColor,看看是不是真的这样。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-04-07
      • 2011-05-24
      • 2021-05-14
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多