简体   繁体   中英

UIImageView in ModalViewController is Ignoring ContentMode - iPhone

I am presenting a modal view with a UIImageView set to content mode fill scale (via the xib). I am setting a UIImage in the modal view class with a thumbnail from the parent class :

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];

Then in the modal view class itself :

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

}

The problem is that when the view appears, it seems to be ignoring the content mode set in the xib and just inserting the image at full size.

This seems like a bug, as when I return to this view the image fits in the UIImage view properly.

Can anyone help ?

Thanks.

OK solved it ! If you manually create the UIImageView in code, it seems to work.

// 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];

More than likely you have the clipsToBounds property set to NO . This will prevent the UIImageView from clipping content outside of its rect. You can set the borderColor of the UIImageView layer to see if this is actually happening.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM