美文网首页
iOS tabbar弹出透明的VC

iOS tabbar弹出透明的VC

作者: 半步天堂iOS | 来源:发表于2016-08-31 17:48 被阅读0次

代码来自于:http://blog.csdn.net/feifeiwuxian/article/details/50388702

今天写项目时遇到一个弹出签到框的需求,我试着直接加了一个imageView在self.view,但是发现被imageView遮挡的button依然可以响应,不知道是只有imageView是如此还是继承于view的控件都是这样。
我并没有深究(没错就是因为懒),转向试着present一个透明的VC 来实现,但是我发现在跳转动画时,可以看到VC.view是透明的,但动画结束之后就变成黑色的了。
网上的很多代码都不能实现这个效果,可能是多了一个tabbar造成的。百度了很久,终于还是找到这个可行的代码。

MKDialogController *controller = [[MKDialogController alloc] init];  
    controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;  
    if ([[UIDevice currentDevice].systemVersion floatValue] >= 8.0) {  
        controller.providesPresentationContextTransitionStyle = YES;  
        controller.definesPresentationContext = YES;  
        controller.modalPresentationStyle = UIModalPresentationOverCurrentContext;  
//        CATransition *animation = [CATransition animation];  
//        animation.duration = 2.0;  
//        animation.timingFunction = UIViewAnimationCurveEaseInOut;  
//        animation.type = @"cameraIrisHollowOpen";  
////        animation.subtype = kCATransitionFromLeft;  
//        [self.view.window.layer addAnimation:animation forKey:nil];  
        [self.tabBarController presentViewController:controller animated:YES completion:nil];  
          
    } else {  
        self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationCurrentContext;  
        [self presentViewController:controller animated:NO completion:nil];  
        self.view.window.rootViewController.modalPresentationStyle = UIModalPresentationFullScreen;  
    }

这里之所以区分iOS8,是因为‘controller.modalPresentationStyle = UIModalPresentationOverCurrentContext; ’在iOS8以后才能有效果

但是还有一个问题,当我这样present一个Nav时,背景又变成黑色的了,希望有大神能给我解答。。

相关文章

网友评论

      本文标题:iOS tabbar弹出透明的VC

      本文链接:https://www.haomeiwen.com/subject/totcettx.html