实现类似qq空间发说说全屏模态半透明页面的效果

iOS 码拜 9年前 (2015-05-11) 959次浏览 0个评论

请问怎么实现类似实现类似qq空间发说说全屏模态半透明页面的效果这种效果
我看到网上有博客写的这个方法,但是实现不了啊
       VCService *vc = [[VCService alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
        [self presentViewController:vc animated:YES completion:^(void){
            vc.view.superview.backgroundColor = [UIColor clearColor];// 背景色透明
        }];

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试
设置一个view 设置alpha 设置透明度等 应该可以实现吧,给底层view个背景色  应该可以 没具体实现过
引用 1 楼 zhangao0086 的回复:

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试

是可以实现,但还要加从下往上出现的动画,还有点击退出感觉有点麻烦,你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

引用 2 楼 u012462238 的回复:

设置一个view 设置alpha 设置透明度等 应该可以实现吧,给底层view个背景色  应该可以 没具体实现过

你好,这个方法我知道,是最基本的方法了,还是谢谢你啦!你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

引用 3 楼 qq_24403369 的回复:
Quote: 引用 1 楼 zhangao0086 的回复:

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试

是可以实现,但还要加从下往上出现的动画,还有点击退出感觉有点麻烦,你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

实现这种效果很简单的,你可以用 VC,也可以直接用 View,而且不要加在之前的 VC上,直接加在 AppDelegate 的window 上比较好

引用 5 楼 zhangao0086 的回复:
Quote: 引用 3 楼 qq_24403369 的回复:
Quote: 引用 1 楼 zhangao0086 的回复:

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试

是可以实现,但还要加从下往上出现的动画,还有点击退出感觉有点麻烦,你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

实现这种效果很简单的,你可以用 VC,也可以直接用 View,而且不要加在之前的 VC上,直接加在 AppDelegate 的window 上比较好

你好 我之前的代码是这样的VCService *vc = [[VCService alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
        [self presentViewController:vc animated:YES completion:^(void){
            vc.view.superview.backgroundColor = [UIColor clearColor];// 背景色透明
        }];
你的意思我好像没听明白,可以做个简单的demo吗,万分感谢了

引用 6 楼 qq_24403369 的回复:
Quote: 引用 5 楼 zhangao0086 的回复:
Quote: 引用 3 楼 qq_24403369 的回复:
Quote: 引用 1 楼 zhangao0086 的回复:

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试

是可以实现,但还要加从下往上出现的动画,还有点击退出感觉有点麻烦,你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

实现这种效果很简单的,你可以用 VC,也可以直接用 View,而且不要加在之前的 VC上,直接加在 AppDelegate 的window 上比较好

你好 我之前的代码是这样的VCService *vc = [[VCService alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
        [self presentViewController:vc animated:YES completion:^(void){
            vc.view.superview.backgroundColor = [UIColor clearColor];// 背景色透明
        }];
你的意思我好像没听明白,可以做个简单的demo吗,万分感谢了

原来你是这样处理的,你试试不用 presentViewController :
[[UIApplication sharedApplication] delegate].window.rootViewController addChildViewController:vc];
[[UIApplication sharedApplication] delegate].window addSubview:vc.view];

用完之后再把两者 remove 掉

引用 7 楼 zhangao0086 的回复:
Quote: 引用 6 楼 qq_24403369 的回复:
Quote: 引用 5 楼 zhangao0086 的回复:
Quote: 引用 3 楼 qq_24403369 的回复:
Quote: 引用 1 楼 zhangao0086 的回复:

你想做这个背景?你可以试试 UIToolBar,把 ToolBar 当成背景试试

是可以实现,但还要加从下往上出现的动画,还有点击退出感觉有点麻烦,你有没有研究过弹出的是一个VC然后覆盖在之前的那个VC上,我之前在 http://blog.csdn.net/kyfxbl/article/details/19336185 这里看到的,我问了楼主但楼主没有回复,按照他的方法我也没有实现成功,所以就到这来问问有没有知道的

实现这种效果很简单的,你可以用 VC,也可以直接用 View,而且不要加在之前的 VC上,直接加在 AppDelegate 的window 上比较好

你好 我之前的代码是这样的VCService *vc = [[VCService alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
        [self presentViewController:vc animated:YES completion:^(void){
            vc.view.superview.backgroundColor = [UIColor clearColor];// 背景色透明
        }];
你的意思我好像没听明白,可以做个简单的demo吗,万分感谢了

原来你是这样处理的,你试试不用 presentViewController :
[[UIApplication sharedApplication] delegate].window.rootViewController addChildViewController:vc];
[[UIApplication sharedApplication] delegate].window addSubview:vc.view];

用完之后再把两者 remove 掉

我运行了之后崩溃了,UIViewControllerHierarchyInconsistency””, reason: “”child view controller:<VCService: 0x7f9c1252cfc0> should have parent view controller:(null) but actual parent is:<ViewController: 0x7f9c124372d0>””

VCService *vc = [[VCService alloc] init];
        vc.modalPresentationStyle = UIModalPresentationFormSheet;// 窗口
        vc.view.backgroundColor = [UIColor whiteColor];
        vc.view.alpha = 0.6f;
        [[[UIApplication sharedApplication] delegate].window.rootViewController addChildViewController:vc];
        [[[UIApplication sharedApplication] delegate].window addSubview:vc.view];

不要设置 vc.modalPresentationStyle,另外这个报错应该是由于你的 vc.view 被重复添加到视图层级中了,自己检查下
引用 9 楼 zhangao0086 的回复:

不要设置 vc.modalPresentationStyle,另外这个报错应该是由于你的 vc.view 被重复添加到视图层级中了,自己检查下

我的vc.view就只添加了一次,检查不出来了,问题就是  [[[UIApplication sharedApplication] delegate].window addSubview:vc.view];这行代码,怎么修改?
       VCService *vc = [[VCService alloc] init];
        [[[UIApplication sharedApplication] delegate].window.rootViewController addChildViewController:vc];
        [[[UIApplication sharedApplication] delegate].window addSubview:vc.view];

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];
之所以不能用 presentViewController 这个方法,是因为 present 后,它的父视图会被隐藏
引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

引用 14 楼 zhangao0086 的回复:
Quote: 引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

我个人觉得能内部实现就内部实现,我很想掌握他的这个方法,但在自己项目里无法实现,你已经教会了我很多东西了,很感谢你!

引用 14 楼 zhangao0086 的回复:
Quote: 引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

请问怎么往toolbar上面加按钮呢,为什么我加了没显示呢?我在VC2里面写的代码,可没有任何效果。。。
 UIToolbar *toobar = (UIToolbar *)[self.view viewWithTag:100];
    for (int i=0; i<6; i++) {
        CGFloat w = (kScreenWidth-60)/3;
        CGFloat h = kScreenHeight/5;
        UIButton *btn = [gergfds createPicturedBelowBtnWithFrame:CGRectMake(10+i%3*(25+w),kScreenHeight*3/5-30+i/3*(10+h), w, h) ImageName:arrPic[i] Target:self Action:@selector(pressFunctionButton:) Title:arrTitle[i]];
       // btn.tag = 1111+i;
        [toobar addSubview:btn];
    }

40分
引用 16 楼 qq_24403369 的回复:
Quote: 引用 14 楼 zhangao0086 的回复:
Quote: 引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

请问怎么往toolbar上面加按钮呢,为什么我加了没显示呢?我在VC2里面写的代码,可没有任何效果。。。
 UIToolbar *toobar = (UIToolbar *)[self.view viewWithTag:100];
    for (int i=0; i<6; i++) {
        CGFloat w = (kScreenWidth-60)/3;
        CGFloat h = kScreenHeight/5;
        UIButton *btn = [gergfds createPicturedBelowBtnWithFrame:CGRectMake(10+i%3*(25+w),kScreenHeight*3/5-30+i/3*(10+h), w, h) ImageName:arrPic[i] Target:self Action:@selector(pressFunctionButton:) Title:arrTitle[i]];
       // btn.tag = 1111+i;
        [toobar addSubview:btn];
    }

看下 toolbar 是不是nil,检查下 button 的frame

引用 17 楼 zhangao0086 的回复:
Quote: 引用 16 楼 qq_24403369 的回复:
Quote: 引用 14 楼 zhangao0086 的回复:
Quote: 引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

请问怎么往toolbar上面加按钮呢,为什么我加了没显示呢?我在VC2里面写的代码,可没有任何效果。。。
 UIToolbar *toobar = (UIToolbar *)[self.view viewWithTag:100];
    for (int i=0; i<6; i++) {
        CGFloat w = (kScreenWidth-60)/3;
        CGFloat h = kScreenHeight/5;
        UIButton *btn = [gergfds createPicturedBelowBtnWithFrame:CGRectMake(10+i%3*(25+w),kScreenHeight*3/5-30+i/3*(10+h), w, h) ImageName:arrPic[i] Target:self Action:@selector(pressFunctionButton:) Title:arrTitle[i]];
       // btn.tag = 1111+i;
        [toobar addSubview:btn];
    }

看下 toolbar 是不是nil,检查下 button 的frame

对  toolbar是nil的,为什么呢?

引用 17 楼 zhangao0086 的回复:
Quote: 引用 16 楼 qq_24403369 的回复:
Quote: 引用 14 楼 zhangao0086 的回复:
Quote: 引用 13 楼 qq_24403369 的回复:
Quote: 引用 11 楼 zhangao0086 的回复:

iOS 8下好像还真有问题,这个代码是可用的:

    UIViewController *vc = [[UIViewController alloc] init];
    vc.view.backgroundColor = [UIColor clearColor];
    
    UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:vc.view.bounds];
    toolbar.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
    [vc.view addSubview:toolbar];
    
    [self.navigationController addChildViewController:vc];
    [self.navigationController.view addSubview:vc.view];

嗯  你的方法是可以  我之前看到一篇博客,http://blog.csdn.net/kyfxbl/article/details/19336185
这种方法你有试过吗?

这种我没试过,应该也可行,不过感觉有些依赖 iOS 的内部实现

请问怎么往toolbar上面加按钮呢,为什么我加了没显示呢?我在VC2里面写的代码,可没有任何效果。。。
 UIToolbar *toobar = (UIToolbar *)[self.view viewWithTag:100];
    for (int i=0; i<6; i++) {
        CGFloat w = (kScreenWidth-60)/3;
        CGFloat h = kScreenHeight/5;
        UIButton *btn = [gergfds createPicturedBelowBtnWithFrame:CGRectMake(10+i%3*(25+w),kScreenHeight*3/5-30+i/3*(10+h), w, h) ImageName:arrPic[i] Target:self Action:@selector(pressFunctionButton:) Title:arrTitle[i]];
       // btn.tag = 1111+i;
        [toobar addSubview:btn];
    }

看下 toolbar 是不是nil,检查下 button 的frame

好了  我的问题解决了,3Q,我把toolbar放在VC2里添加了,没在VC1里添加


CodeBye 版权所有丨如未注明 , 均为原创丨本网站采用BY-NC-SA协议进行授权 , 转载请注明实现类似qq空间发说说全屏模态半透明页面的效果
喜欢 (0)
[1034331897@qq.com]
分享 (0)

文章评论已关闭!