UICustomViewController *customvc = [UICustomViewController new];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:customvc];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[self presentViewController:customvc animated:YES completion:nil];
需要在UICustomViewController的 viewWillAppear: 方法中 设置 frame
-
(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
GCFloat topY = 120;
self.navigationController.view.superview.frame = CGRectMake(0, topY, SCREEN_WIDTH, SCREEN_HEIGHT - topY);
}
以上是可根据内容设置显示区域大小
还有一种是iOS15的显示半屏或者全屏的方法
控制器的 sheetPresentationController 属性
UISheetPresentationController *sheet = self.sheetPresentationController;
sheet.detents = @[UISheetPresentationControllerDetent.mediumDetent,
UISheetPresentationControllerDetent.largeDetent ];
sheet.smallestUndimmedDetentIdentifier = UISheetPresentationControllerDetentIdentifierMedium;
sheet.prefersScrollingExpandsWhenScrolledToEdge = false;
sheet.prefersEdgeAttachedInCompactHeight = true;
sheet.widthFollowsPreferredContentSizeWhenEdgeAttached = true;
类似于调取原生分享时的效果,可以半屏,往上拖动就是全屏