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

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

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

- (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.
*/

时间: 2024-08-29 00:09:50

iOS 模拟出一个半透明的ViewController presentViewController 实现的相关文章

在iOS上present一个半透明的viewController

UIViewController *viewController = [[UIViewController alloc]init]; UIViewController* controller = self.view.window.rootViewController;viewController.view.backgroundColor = [UIColor blackColor]; viewController.view.alpha = 0.5f; controller.modalPresen

presentViewController弹出一个半透明的UIViewController

UIViewController 推出另外一个半透明的UIViewController UIViewController *controller = [[UIViewController alloc]init]; if ([[[UIDevice currentDevice] systemVersion] floatValue]>=8.0) { nav.modalPresentationStyle=UIModalPresentationOverCurrentContext; }else{ nav.

IOS 弹出模态透明的ViewController

ViewController *vcObj = [[ViewController alloc] initWithNibName:NSStringFromClass([ViewController class]) bundle:nil];    UINavigationController *navCon = [[UINavigationController alloc] initWithRootViewController:vcObj];        if ([[UIDevice curren

present一个半透明的ViewController的方法

RecommandViewController *recommandVC = [[RecommandViewController alloc]init]; if([[[UIDevice currentDevice] systemVersion] floatValue] >= 8.0){ recommandVC.modalPresentationStyle= UIModalPresentationOverCurrentContext|UIModalPresentationFullScreen;//

用两个队列模拟实现一个栈的过程

栈具有"后进先出"的特点,即某个元素最后进入栈,却最先出栈:队列具有"先进先出"的特点,即元素从队尾依次进队列,依次从队头出队列:现在用两个队列模拟实现一个栈的过程,详细过程请看下面这张本人制作的gif图: 实现代码: #include <iostream> using namespace std; #include <queue> template <typename T> class Stack { public: void

用两个栈模拟实现一个队列

题目:如何用两个栈模拟实现一个队列?  如果这两个堆栈的容量分别是m和n(m>n),你的方法能保证的队列容量是多少?(这里讨论的是顺序栈,如果是链式栈的话完全没有必要考虑空间) 分析:栈的特点是“后进先出(LIFO)”,而队列的特点是“先进先出(FIFO)”.用两个栈模拟实现一个队列的基本思路是:用一个栈作为存储空间,另一个栈作为输出缓冲区,把元素按顺序压入两栈(模拟的队列),并按此顺序出队并输出即可. 如下图,用容量为m的栈作为存储空间,容量为n的栈作为输出缓冲区,一开始先将n个元素压入(pu

自己动手模拟开发一个简单的Web服务器

开篇:每当我们将开发好的ASP.NET网站部署到IIS服务器中,在浏览器正常浏览页面时,可曾想过Web服务器是怎么工作的,其原理是什么?“纸上得来终觉浅,绝知此事要躬行”,于是我们自己模拟一个简单的Web服务器来体会一下. 一.请求-处理-响应模型 1.1 基本过程介绍 每一个HTTP请求都会经历三个步凑:请求-处理-响应:每当我们在浏览器中输入一个URL时都会被封装为一个HTTP请求报文发送到Web服务器,而Web服务器则接收并解析HTTP请求报文,然后针对请求进行处理(返回指定的HTML页面

网页开发笔记【一】创建一个半透明的页面

近来正在温习网页制作,系列<网页开发笔记>记录本人在解决网页开发过程中遇到的问题以及解决方案. 半透明的页面在网页开发中使用的比较广泛,尤其在web app中,这种设计使用的地方更为广泛,本文记录这种半透明的页面的开发方法. 半透明页面常用于用户注册,这时候弹出一个页面能在不离开当前页面的情况下完成注册. 如百度的登陆界面所示. 我的处理方法如下: 首先在页面写一个div,这个div平时display设置为none,当需要的时候设置为display:block; 这个div(设其id为popu

java模拟而一个电话本操作

哈哈,大家平时都在使用电话本,下面使用java来模拟而一个简单的电话本吧... 首先给出联系人的抽象类 package net.itaem.po; /** * * 电话人的信息 * */ public class User { private String name; private String phoneNumber; private String companyName; private String email; private String address; private Strin