こういう人に向けて発信しています。
・ViewControllerを表示して勝手に閉じられてしまって困っている人
・Objective-C中級者
・Swift中級者
iOS13でのモーダル表示
こちらの記事ではSwiftのみ記載があったので、
Objective-Cの内容も合わせて補足して記事として出します。
また、ネット上で調べてもうまく検索でヒットしないので
今回の記事をまとめてさせていただきました。
Objective-Cにつきましては記事を参考にせず
動作確認の上掲載しております。
Objective-C
UIViewController *vc = [[UIViewController alloc]init];
vc.modalPresentationStyle = UIModalPresentationFullScreen; //表示形式の選択
setting.modalInPopover = YES; //YESにするとスワイプで消えなくなる。
[self presentViewController:vc animated:YES completion:nil];
Swift
let vc = UIViewController()
vc.modalPresentationStyle = .fullScreen;
vc.isModalInPresentation = true;
present(vc, animated: false, completion: nil)
上記補足
閉じれないとは書いていますが、少しだけ下がるような挙動をします。
ただしiOSのiMessageなども同様挙動する事から
完全にスワイプするのはオフには難しいのかと思っております。
下記内容は補足となります。
例えばFormSheetのサイズを固定化したい時(Objective-C)
UIViewController *vc = [[UIViewController alloc]init];
vc.modalPresentationStyle = UIModalPresentationFormSheet;
//モーダルビューのサイズを変更
float frameWidth = 550;
float frameHeight = 260;
vc.preferredContentSize = CGSizeMake(frameWidth, frameHeight);
例えばFormSheetのサイズを固定化したい時(Swift)
//サイズ指定する
let frameWidth :CGFloat = 550
let frameHeight : CGFloat = 260;
vc.preferredContentSize = CGSize(width: frameWidth, height: frameHeight)