很多时候需要在原视图上弹出一个自定义视图让用户确认一些东西. 通常的做法一般使用UIAlertView/UIAlertController. 但是做为自定义它们的风格可能与app不符.
思路如下:
1) 创建一个UIViewController,背景是一个UIImageView,Autolayout至全屏,图片选用半透明的,目标是为了显示前一页的部分内容
2) 通过presentViewController:animated:completion:来弹出视图
3) 注意弹出的视图的背景颜色要改成clearColor,否则无法透明
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
if ([NSProcessInfo instancesRespondToSelector:@selector(isOperatingSystemAtLeastVersion:)]){
viewController.providesPresentationContextTransitionStyle = YES;
viewController.definesPresentationContext = YES;
[viewController setModalPresentationStyle:UIModalPresentationOverCurrentContext];
}
else{
[self setModalPresentationStyle:UIModalPresentationCurrentContext];
[self.navigationController setModalPresentationStyle:UIModalPresentationCurrentContext];
}
[self presentViewController:viewController animated:YES completion:nil];
参考图:
本文介绍了一种在iOS应用中创建自定义对话框的方法,利用UIViewController实现覆盖当前上下文的透明背景视图,并展示了如何调整视图控制器的过渡样式以平滑地呈现对话框。

823

被折叠的 条评论
为什么被折叠?



