iOS-修改modal出来的控制器的大小

时间:2022-03-01 15:27:36

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
    static BOOL showFlag = NO;

if (!showFlag) {
        XZHomeViewController *home = [[XZHomeViewController alloc] init];
        XZNavigationController *nav = [[XZNavigationController alloc] initWithRootViewController:home];

nav.modalPresentationStiyle = UIModalPresentationFormSheet;
//        nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
        [self presentViewController:nav animated:YES completion:nil];

// 修改modal出来的控制器的大小
        nav.preferredContentSize = CGSzeMake(150, 150); // 或者  home.preferredContentSize = CGSizeMake(150, 150);
    } else {
        [self dismissViewControllerAnimated:YES completion:nil];
    }
    showFlag = !showFlag;