iOS:使用全屏图像显示模态视图控制器

时间:2013-12-02 16:24:53

标签: ios uiimageview

我想在点按缩略图时显示全屏图像。现在我正在呈现一个模态视图控制器,但图像不在屏幕中心:

enter image description here

这是我在模态视图控制器中用来呈现视图控制器的代码:

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

如何在视图控制器中居中显示此图像?

1 个答案:

答案 0 :(得分:4)

你试过[image view setCenter:self.view.center]吗? 根据屏幕居中,但如果你想以modalCon为中心,则将self.view替换为modalCon.view