Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

iOS: Show Modal View Controller with full screen image

I want to show a fullscreen image when a thumbnail is tapped. Right now I'm presenting a modal view controller, but the image is not centered in the screen:

enter image description here

Here's the code I'm using in the modal view controller to present the view controller:

UIViewController *modalCon = [[UIViewController alloc] init];

modalCon.view.backgroundColor=[UIColor blackColor];
modalCon.view.userInteractionEnabled=YES;

UIImageView *imageView = [[UIImageView alloc] initWithFrame:modalCon.view.frame];
imageView.contentMode=UIViewContentModeScaleAspectFit;
imageView.image=coverImage.image;

[modalCon.view addSubview:imageView];

UITapGestureRecognizer *modalTap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismissModalView)];
[modalCon.view addGestureRecognizer:modalTap];

[self presentViewController:modalCon animated:YES completion:nil];

How do I get this image centered in the view controller?

like image 948
James Harpe Avatar asked Oct 02 '22 06:10

James Harpe


1 Answers

did you try [image view setCenter:self.view.center] that one centres according to screen but if you want to centre to modalCon then replace self.view to modalCon.view

like image 150
savana Avatar answered Oct 13 '22 11:10

savana