我想在点按缩略图时显示全屏图像。现在我正在呈现一个模态视图控制器,但图像不在屏幕中心:
这是我在模态视图控制器中用来呈现视图控制器的代码:
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];
如何在视图控制器中居中显示此图像?
答案 0 :(得分:4)
[image view setCenter:self.view.center]
吗?
根据屏幕居中,但如果你想以modalCon为中心,则将self.view
替换为modalCon.view