码迷,mamicode.com
首页 > 移动开发 > 详细

iOS 模拟出一个半透明的ViewController presentViewController 实现

时间:2015-05-26 16:07:15      阅读:140      评论:0      收藏:0      [点我收藏+]

标签:

最近项目有需求, 需要模态初一个半透明的视图, 好多人都碰到这个问题吧, 在目标视图中设置背景颜色然后发现模态动作结束后变成了黑色或者不是半透明的颜色。

所以今天来告诉大家解决方案

- (IBAction)Avtion1:(id)sender {

    TestViewController * testVC = [TestViewController new];

    self.definesPresentationContext = YES; //self is presenting view controller
    testVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:.4];
    testVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;

    [self presentViewController:testVC animated:YES completion:nil];
}
  • definesPresentationContext
/*
  Determines which parent view controller‘s view should be presented over for presentations of type
  UIModalPresentationCurrentContext.  If no ancestor view controller has this flag set, then the presenter
  will be the root view controller.
*/
  • backgroundColor
设置你的背景颜色
  • modalPresentationStyle
/*
  Defines the transition style that will be used for this view controller when it is presented modally. Set
  this property on the view controller to be presented, not the presenter.  Defaults to
  UIModalTransitionStyleCoverVertical.
*/

iOS 模拟出一个半透明的ViewController presentViewController 实现

标签:

原文地址:http://blog.csdn.net/lihongli528628/article/details/46009141

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!