如何模態出一個半透明頁面
一般在做自定義彈框時或者點選展示大圖時用的較多。不說了上程式碼https://github.com/YST521/DEMOLIST.git
//第一步A頁面跳轉到B頁面
MOdalPopController * popVC = [MOdalPopController new];
popVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
popVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
[self presentAnimal]; //跳轉動畫
[self.navigationController presentViewController:popVC animated:NO completion:nil];
//
-(void)presentAnimal{
CATransition *animation = [CATransition animation];
animation.duration = 0.3;
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromTop;
[self.view.window.layer addAnimation:animation forKey:nil];
[self dismissViewControllerAnimated:NO completion:0];
}
//如果[self.navigationController presentViewController:popVC animated:NO completion:nil];裡面動畫為YES則是模態的那幾種動畫效果
B頁面。dismiss 同樣去掉了動畫效果 重新添加了動畫
-(void)dismiss{
CATransition *animation = [CATransition animation];
animation.duration = 0.3;
animation.type = kCATransitionFade;
animation.subtype = kCATransitionFromTop;
[self.view.window.layer addAnimation:animation forKey:nil];
[self dismissViewControllerAnimated:NO completion:0];
}