記錄工程中遇到的變態(tài)產(chǎn)品的變態(tài)問題,吧啦吧啦……
搜索的資料,以及實(shí)驗(yàn),貌似只能iOS 8+適用,不過iOS 7已經(jīng)趨近淘汰,先不考慮了咯……
一 彈出半透明界面
先上效果圖:



其實(shí)真的很簡單,直接上代碼吧
//彈出ViewController
XXxViewController *xVC = [XXxViewController new];
//設(shè)置ViewController的背景顏色及透明度
xVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
//設(shè)置ViewController的模態(tài)模式,即ViewController的顯示方式
xVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
//加載模態(tài)視圖
[self presentViewController:xVC animated:YES completion:^{
}];
彈出NavigationController這個(gè)不用多解釋吧,當(dāng)你看到這個(gè)帖子的需求的時(shí)候,我相信你已經(jīng)會(huì)把ViewController包一層NavigationController模態(tài)彈出了。
//彈出NavigationController
XXxViewController *xVC = [XXxViewController new];
//設(shè)置ViewController的背景顏色及透明度
xVC.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.5];
//設(shè)置NavigationController根視圖
UINavigationController *navigation = [[UINavigationController alloc]initWithRootViewController:xVC];
//設(shè)置NavigationController的模態(tài)模式,即NavigationController的顯示方式
navigation.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.modalPresentationStyle = UIModalPresentationCurrentContext;
//加載模態(tài)視圖
[self presentViewController:navigation animated:YES completion:^{
}];
Over完成,試試吧,其實(shí)真的很簡單!
總結(jié)
關(guān)于模態(tài)的modalPresentationStyle解釋。(嗯,我也是粘別人的~)
UIModalPresentationStyle即viewcontroller的顯示方式
typedefNS_ENUM(NSInteger, UIModalPresentationStyle) {
UIModalPresentationFullScreen =0,//由下到上,全屏覆蓋
UIModalPresentationPageSheet,//在portrait時(shí)是FullScreen,在landscape時(shí)和FormSheet模式一樣。
UIModalPresentationFormSheet,// 會(huì)將窗口縮小,使之居于屏幕中間。在portrait和landscape下都一樣,但要注意landscape下如果軟鍵盤出現(xiàn),窗口位置會(huì)調(diào)整。
UIModalPresentationCurrentContext,//這種模式下,presented VC的彈出方式和presenting VC的父VC的方式相同。
UIModalPresentationCustom,//自定義視圖展示風(fēng)格,由一個(gè)自定義演示控制器和一個(gè)或多個(gè)自定義動(dòng)畫對(duì)象組成。符合UIViewControllerTransitioningDelegate協(xié)議。使用視圖控制器的transitioningDelegate設(shè)定您的自定義轉(zhuǎn)換。
UIModalPresentationOverFullScreen,//如果視圖沒有被填滿,底層視圖可以透過
UIModalPresentationOverCurrentContext,//視圖全部被透過
UIModalPresentationPopover,
UIModalPresentationNone ,
};
二 自定義彈出動(dòng)畫
記錄工程中遇到的變態(tài)產(chǎn)品的變態(tài)問題 too,吧啦吧啦……
對(duì)于系統(tǒng)的模態(tài)彈出的方式只有四種:
typedef NS_ENUM(NSInteger, UIModalTransitionStyle) {
UIModalTransitionStyleCoverVertical = 0, // 底部滑入。
UIModalTransitionStyleFlipHorizontal, // 水平翻轉(zhuǎn)。
UIModalTransitionStyleCrossDissolve, // 交叉溶解。
UIModalTransitionStylePartialCurl, // 翻頁。
};
氮素?fù)醪蛔‘a(chǎn)品(gou)想從上往下彈出,來吧,我們直接寫動(dòng)畫吧~~
彈出
//自定義動(dòng)畫
CATransition *animation = [CATransition animation];
animation.duration = 0.3;
animation.type = kCATransitionMoveIn;
animation.subtype = kCATransitionFromBottom;
[self.view.window.layer addAnimation:animation forKey:nil];
//彈出ViewController
XXxViewController *xVC = [XXxViewController new];
[self presentViewController:xVC animated:YES completion:^{
}];
消失(原路返回消失)
CATransition *animation = [CATransition animation];
animation.duration = 0.3;
animation.type = kCATransitionReveal;
animation.subtype = kCATransitionFromTop;
[self.view.window.layer addAnimation:animation forKey:nil];
[self dismissViewControllerAnimated:NO completion:0];
總結(jié)
關(guān)于type和subtype:
setType:有四種類型:
kCATransitionFade //交叉淡化過渡
kCATransitionMoveIn //移動(dòng)覆蓋原圖
kCATransitionPush //新視圖將舊視圖推出去
kCATransitionReveal //底部顯出來
Subtype:有四種類型:
kCATransitionFromRight
kCATransitionFromLeft (默認(rèn)值)
kCATransitionFromTop
kCATransitionFromBottom
目前內(nèi)容已經(jīng)完成,有什么好的建議歡迎討論O(∩_∩)O哈哈哈~