iOS透明viewControler

有时候在跳转控制器的时候需要,跳转到当前控制器上方,显示一个可以看到下方原来控制器的半透明控制器。

如下图:


跳转方式可以修改这句代码来实现,激变,从下往上。或者也可以自定义一些动画。(已经被我注释掉的那些)

controller.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;

跳转的时候根据要跳转到哪一层控制器上方的情况,修改如下代码

 [self.tabBarController presentViewController:controller animated:YES completion:nil] (这里是跳转到tabBar控制器的上方。)


第一个控制器代码

#import "ViewController.h"
#import "MKDialogController.h"
@interface ViewController ()

@end

@implementation ViewController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view, typically from a nib.
//    fade     //交叉淡化过渡(不支持过渡方向)
//    push     //新视图把旧视图推出去
//    moveIn   //新视图移到旧视图上面
//    reveal   //将旧视图移开,显示下面的新视图
//    cube     //立方体翻滚效果
//    oglFlip  //上下左右翻转效果
//    suckEffect   //收缩效果,如一块布被抽走(不支持过渡方向)
//    rippleEffect //滴水效果(不支持过渡方向)
//    pageCurl     //向上翻页效果
//    pageUnCurl   //向下翻页效果
//    cameraIrisHollowOpen  //相机镜头打开效果(不支持过渡方向)
//    cameraIrisHollowClose //相机镜头关上效果(不支持过渡方向)
}
- (IBAction)btnClick:(UIButton *)sender {
    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;
    }
}



- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

@end

要跳转的控制器代码

#import "MKDialogController.h"

@interface MKDialogController ()

@end

@implementation MKDialogController

- (void)viewDidLoad {
    [super viewDidLoad];
    // Do any additional setup after loading the view.
    self.view.backgroundColor = [UIColor clearColor];
    UIView *alphaView = [[UIView alloc] initWithFrame:self.view.frame];
    UIView *baseView = [[UIView alloc] initWithFrame:self.view.frame];
    alphaView.backgroundColor = [UIColor clearColor];
    baseView.backgroundColor = [UIColor blackColor];
    baseView.alpha = 0.8;
    [self.view addSubview:baseView];
    [self.view addSubview:alphaView];
    
    UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
    button.frame = CGRectMake(20, 178, 100, 60);
    [button setTitle:@"点我返回" forState:UIControlStateNormal];
    button.backgroundColor = [UIColor brownColor];
    
    [alphaView addSubview:button];
    [button addTarget:self action:@selector(dissmiss) forControlEvents:UIControlEventTouchUpInside];
}

- (void)dissmiss{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

/*
#pragma mark - Navigation

// In a storyboard-based application, you will often want to do a little preparation before navigation
- (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
    // Get the new view controller using [segue destinationViewController].
    // Pass the selected object to the new view controller.
}
*/

@end


评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值