This is the ninth day of my participation in the August More Text Challenge. For details, see “August More Text Challenge” juejin.cn/post/698796…
preface
Requirement: Use the current VC interface as the background image of another VC (push another view controller with transparent background in the current view)
Specific application scenarios:
- Payment details for order
- Publish a selection of merchandise categories
- Feedback page
Payment details for order
This interface belongs to a separate payment plugin
Implementation ideas:
- The modal system at using styles: UIModalPresentationOverCurrentContext
‘- A presentation style where the content is displayed over another view controller’s content
`)
- Capture the current screen
I, implementation scheme
It is recommended to use the system’s own modal style for requirements because of better performance and simpler implementation
1.1 Use the built-in modal style
To set modalPresentationStyle UIModalPresentationOverCurrentContext, and set the color mask
CategoryViewController *tmp = [CategoryViewController new];
tmp.modalPresentationStyle = UIModalPresentationOverCurrentContext;
// Set the mask color
[tmp view].backgroundColor = STModalWindowDefaultBackgroundColor;
[self.navigationController presentViewController:tmp animated:YES completion:^{
}];
Copy the code
The subview background color can be clearColor or any other color as required.
- (void)viewDidLoad {
[super viewDidLoad];
// Set the VCView background color to clearColor
[self vcView].backgroundColor =[UIColor clearColor] ;
}
Copy the code
Settings Click the mask to return to the previous screen
Set priority tableView click event, below the selected cell and click button events 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));
// Set subview constraint (height)
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(@" Set tableView click event priority lower than cell select event");
}];
cutTap1.cancelsTouchesInView = NO;// Set tableView click event priority, lower than the cell selected event
[tmp.tableView addGestureRecognizer:cutTap1];
}
return _vcView;
}
Copy the code
Effect: Release a selection of merchandise categories
Download address: download.csdn.net/download/u0…
The article addresses: kunnan.blog.csdn.net/article/det…
Video address: live.csdn.net/v/167208
Application scenarios of commodity business category selection view:
1. Select commodity category when releasing commodities; 2. Select business category when importing commodities; 3
You can use the run API to control modal styles globally
Resources from CSDN download the complete demo source: download.csdn.net/download/u0… Flexible control mode shows the view style of the article: blog.csdn.net/z929118967/…
For more content, please pay attention to the official account: iOS Reverse
- (NSMutableArray *)OverCurrentContextClasss{
if(_OverCurrentContextClasss == nil){
_OverCurrentContextClasss = [NSMutableArray array];
/ /.. Publish merchandise - Select merchandise category
[_OverCurrentContextClasss addObject:@"ERPSelect_commodity_categoryViewController"];
// Image browser
[_OverCurrentContextClasss addObject:@"KNImageBrowserViewController"];
// Select wechat activities
[_OverCurrentContextClasss addObject:@"CRMSelectedWechantActivityTypeVC"];
}
return _OverCurrentContextClasss;
}
Copy the code
1.2 Intercepting the current View
The feedback page automatically generates screenshots
Note: Screenshots are created before the feedback page is clicked
【 principle article 】 (https://kunnan.blog.csdn.net/article/details/113444297)
1.3 Summary of the use of dismiss
Application 1: Custom WebViewController. When you finish using your photo album, the controller where the WebView resides also dies
Problem: A feature of Apple. So when we have N view controllers in the mode, we just dismiss any one of them, we dismiss all of the modes after that, So that causes the H5 of the WebView in the MODAL UIViewController to pop up Camera/ImagePicker, When UIDocumentMenuViewController disappear will cause the WebView controller was also killed.
solution So make dismissViewControllerAnimated call time, or let UIDocumentMenuViewController find presentingViewController can.
To obtain the source code of Demo, please pay attention to the official number: iOS Reverse
Github.com/zhangkn/KNU…
Application 2: To modal all ViewController dismiss at once, just use present ViewController to dismiss
[t setDissblock:^(id _Nonnull sender) {
[weakSelf.presentingViewController dismissViewControllerAnimated:YES completion:nil];
}];
Copy the code
see also
Git branch management tutorial
Mp.weixin.qq.com/s/-63si1cRx…