使用:
GW_MoreMatchEntryCTRL *moreMatchVC = [[GW_MoreMatchEntryCTRL alloc] init];
// 或者:在这里设置
// moreMatchVC.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self.navigationController presentViewController:moreMatchVC animated:NO completion:nil];
VC.h:
#import <UIKit/UIKit.h>
NS_ASSUME_NONNULL_BEGIN
@interface GW_MoreMatchEntryCTRL : UIViewController
@end
NS_ASSUME_NONNULL_END
VC.m:
#import "GW_MoreMatchEntryCTRL.h"
@interface GW_MoreMatchEntryCTRL ()
@property (nonatomic, strong) UIView *backView;
@property (nonatomic, strong) UIVisualEffectView *effextView; // 毛玻璃(设置其 透明度 effextView.alpha)
@end
@implementation GW_MoreMatchEntryCTRL
- (instancetype)init
{
self = [super init];
if (self) {
// 需要在push之前添加这行 modalPresentationStyle
self.modalPresentationStyle = UIModalPresentationOverCurrentContext;
self.view.backgroundColor = UIColor.clearColor;
}
return self;
}
- (void)viewDidLoad {
[super viewDidLoad];
[self setupUI];
}
- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
[UIView animateWithDuration:0.25 animations:^(void) {
self.backView.frame = CGRectMake(0, 0, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
// self.backView.backgroundColor = [UIColor colorWithRed:0/255.f green:0/255.f blue:0/255.f alpha:.3f];
}completion:^(BOOL finished) {
// self.backView.backgroundColor = [UIColor colorWithRed:0/255.f green:0/255.f blue:0/255.f alpha:.3f];
self.backView.backgroundColor = [UIColor clearColor];
// 毛玻璃效果
// _effextView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
// self.effextView.alpha = 0.5;
// self.effextView.frame = [UIScreen mainScreen].bounds;
[self.backView addSubview:self.effextView];
}];
}
- (UIVisualEffectView *)effextView {
if (!_effextView) {
_effextView = [[UIVisualEffectView alloc] initWithEffect:[UIBlurEffect effectWithStyle:UIBlurEffectStyleLight]];
self.effextView.alpha = 0.5;
self.effextView.frame = [UIScreen mainScreen].bounds;
}
return _effextView;
}
- (void)viewWillDisappear:(BOOL)animated {
[super viewWillDisappear:animated];
[self.navigationController setNavigationBarHidden:YES animated:YES];
}
- (void)setupUI {
_backView = [[UIView alloc] initWithFrame:CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height)];
self.backView.backgroundColor = [UIColor clearColor];
[self.view addSubview:self.backView];
UITapGestureRecognizer *tap = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(dismiss:)];
self.backView.userInteractionEnabled = YES;
[self.backView addGestureRecognizer:tap];
}
- (void)dismiss:(UIGestureRecognizer *)tap {
[UIView animateWithDuration:0.25 animations:^(void) {
self.backView.frame = CGRectMake(0, [UIScreen mainScreen].bounds.size.height, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height);
self.effextView.alpha = 0;
}completion:^(BOOL finished) {
self.backView.backgroundColor = UIColor.clearColor;
[self dismissViewControllerAnimated:NO completion:nil];
}];
}
@end
网友评论