//--------------------------------------------
//SGH0524PresentAViewController.m
#import "SGH0524PresentAViewController.h"
#import <Masonry.h>
#import "SGH0524PresentBViewController.h"
@interface SGH0524PresentAViewController ()
@end
@implementation SGH0524PresentAViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
UIButton *button = ({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:16];
button.layer.cornerRadius = 3;
button.clipsToBounds = YES;
button.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
button.tag = 104;
[button setTitle:@"A Controller Button" forState:UIControlStateNormal];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[button addTarget:self action:@selector(p_presentClick) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:button];
button;
});
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.equalTo(self.view).offset( 100 );
}];
}
-(void)p_presentClick {
SGH0524PresentBViewController *vc = [[SGH0524PresentBViewController alloc]init];
//self.definesPresentationContext = YES;
//大于等于 iOS8.0
if ([[[UIDevice currentDevice] systemVersion] compare:@"8.0" options:NSNumericSearch] != NSOrderedAscending) {
vc.modalPresentationStyle = UIModalPresentationOverCurrentContext;
}
else {
vc.modalPresentationStyle = UIModalPresentationCurrentContext;
vc.navigationController.modalPresentationStyle = UIModalPresentationCurrentContext;
}
[self presentViewController:vc animated:YES completion:^{ }];
}
@end
//--------------------------------------------
//SGH0524PresentBViewController.m
#import "SGH0524PresentBViewController.h"
#import <Masonry.h>
@interface SGH0524PresentBViewController ()
@end
@implementation SGH0524PresentBViewController
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
self.view.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
UIButton *button = ({
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
button.titleLabel.font = [UIFont systemFontOfSize:16];
button.layer.cornerRadius = 3;
button.clipsToBounds = YES;
button.backgroundColor = [UIColor colorWithRed:0 green:0 blue:0 alpha:0.3];
button.tag = 104;
[button setTitle:@"B Controller Button" forState:UIControlStateNormal];
button.titleLabel.textAlignment = NSTextAlignmentCenter;
[self.view addSubview:button];
button;
});
[button mas_makeConstraints:^(MASConstraintMaker *make) {
make.centerX.equalTo(self.view);
make.top.equalTo(self.view).offset( 150 );
}];
}
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event {
[self dismissViewControllerAnimated:YES completion:nil];
}
@end