這是我參與8月更文挑戰的第9天,活動詳情查看: 8月更文挑戰」 juejin.cn/post/698796… 」git
需求:將當前的VC的界面做爲另外一個VC的背景圖片(在當前視圖中推出另一個背景透明的視圖控制器)github
具體的應用場景:瀏覽器
- 下單的的付款詳情
- 發佈商品的選擇商品類目
- 反饋頁面
下單的的付款詳情
這個界面屬於獨立的支付插件
微信
實現思路:markdown
- 使用系統自帶的modal樣式:UIModalPresentationOverCurrentContext
`- A presentation style where the content is displayed over another view controller’s contentapp
`)ide
- 截取當前屏幕
推薦使用系統自帶的modal樣式實現需求,由於性能更好,實現也簡單oop
設置modalPresentationStyle爲UIModalPresentationOverCurrentContext
,並設置蒙版顏色post
CategoryViewController *tmp = [CategoryViewController new];
tmp.modalPresentationStyle = UIModalPresentationOverCurrentContext;
//設置蒙版顏色
[tmp view].backgroundColor = STModalWindowDefaultBackgroundColor;
[self.navigationController presentViewController:tmp animated:YES completion:^{
}];
複製代碼
子視圖背景顏色可根據須要爲clearColor,或者其餘顏色。性能
- (void)viewDidLoad {
[super viewDidLoad];
//設置VCView背景顏色爲clearColor
[self vcView].backgroundColor =[UIColor clearColor] ;
}
複製代碼
設置點擊蒙版回到上個界面
設置tableView的點擊事件優先級,低於cell的選中事件以及按鈕的點擊事件
UIControlEventTouchUpInside
- (CRMSelectedWechantActivityTypeV *)vcView{
if (!_vcView) {
CRMSelectedWechantActivityTypeV *tmp = [[CRMSelectedWechantActivityTypeV alloc] initWithViewModel:self.viewModel];
_vcView= tmp;
__weak __typeof__(self) weakSelf = self;
[self.view addSubview:tmp];
[tmp mas_makeConstraints:^(MASConstraintMaker *make) {
CGFloat CategoriesH =1*(142+12);
make.height.mas_equalTo(kAdjustRatio(78+CategoriesH+90));
make.left.equalTo(weakSelf.view).offset(kAdjustRatio(0));
make.bottom.equalTo(weakSelf.view);
make.right.equalTo(weakSelf.view).offset(-kAdjustRatio(0));
// 設置子視圖約束(高度)
make.height.equalTo(weakSelf.view).multipliedBy(0.45).offset(kAdjustRatio(self.viewModel.selectedplatProductCategories.count*50+50));
}];
UITapGestureRecognizer *cutTap = [[UITapGestureRecognizer alloc] init];
[[cutTap rac_gestureSignal] subscribeNext:^(id x) {
[weakSelf dismissViewControllerAnimated:YES completion:nil];
}];
[weakSelf.view addGestureRecognizer:cutTap];
UITapGestureRecognizer *cutTap1 = [[UITapGestureRecognizer alloc] init];
[[cutTap1 rac_gestureSignal] subscribeNext:^(id x) {
NSLog(@" 設置tableView的點擊事件優先級,低於cell的選中事件 ");
}];
cutTap1.cancelsTouchesInView = NO;// 設置tableView的點擊事件優先級,低於cell的選中事件
[tmp.tableView addGestureRecognizer:cutTap1];
}
return _vcView;
}
複製代碼
效果:發佈商品的選擇商品類目
下載地址:download.csdn.net/download/u0…
文章地址:kunnan.blog.csdn.net/article/det…
商品經營類目選擇視圖的應用場景:
一、發佈商品時選擇商品類目 二、商戶進件選擇經營類目 三、購物類app下單界面的商品類目篩選
你可使用運行API進行全局控制modal的樣式
從CSDN資源下載完整demo源碼:download.csdn.net/download/u0… 靈活控制模態展現的視圖樣式的文章:blog.csdn.net/z929118967/…
更多內容請關注公衆號:iOS逆向
- (NSMutableArray *)OverCurrentContextClasss{
if(_OverCurrentContextClasss == nil){
_OverCurrentContextClasss = [NSMutableArray array];
//.. 發佈商品- 選擇商品類目
[_OverCurrentContextClasss addObject:@"ERPSelect_commodity_categoryViewController"];
// 圖片瀏覽器
[_OverCurrentContextClasss addObject:@"KNImageBrowserViewController"];
// 選擇微信活動
[_OverCurrentContextClasss addObject:@"CRMSelectedWechantActivityTypeVC"];
}
return _OverCurrentContextClasss;
}
複製代碼
反饋頁面自動生成截圖
注意:截圖在彈反饋頁面以前create
【原理文章】(https://kunnan.blog.csdn.net/article/details/113444297)
應用1:自定義WebViewController,使用完相冊以後致使WebView 所在的控制器也被幹掉的問題
問題:蘋果的一個特性。當模態出N個ViewController以後,只須要dismiss任意一個,都會dismiss它以後的全部模態試圖 ,所以會致使modal模態出來的UIViewController中WebView的H5彈出Camera/ImagePicker 時,當UIDocumentMenuViewController消失的時候會致使WebView 所在的控制器也被幹掉。
解決思路 因此使dismissViewControllerAnimated調用一次,或者讓UIDocumentMenuViewController找不到presentingViewController便可。
獲取demo源碼,請關注公衆號:iOS逆向
應用2:想要一次性把模態出來的全部ViewController dismiss,只須要使用presentingViewController進行dismiss便可
[t setDissblock:^(id _Nonnull sender) {
[weakSelf.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}];
複製代碼
git 代碼分支管理教程