我在objective-c中有这个旧代码,它在自定义框架中的当前视图中显示一个视图控制器:
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:@"Main" bundle:nil];
UIViewController *viewController;
viewController = nil;
PopoverChoiseTableViewController *viewControllers = (PopoverChoiseTableViewController *)[storyboard instantiateViewControllerWithIdentifier:@"modalPopoverChoise"];
viewController = viewControllers;
[self.navigationController.navigationBar setUserInteractionEnabled:NO];
viewController.modalPresentationStyle = UIModalPresentationOverCurrentContext;
[self presentViewController:viewController animated:NO completion:^{
viewController.view.superview.frame = CGRectMake(0, 0, 200, 255);
viewController.view.superview.center = self.view.center;
viewController.view.layer.cornerRadius = 5;
viewController.view.layer.masksToBounds = YES;
}];
我试图在swift中做同样的事情:
let storyboard = UIStoryboard(name: "Main", bundle: nil)
let vc = storyboard.instantiateViewControllerWithIdentifier(identifier)
vc.modalPresentationStyle = UIModalPresentationStyle.PageSheet
self.presentViewController(vc, animated: true, completion: nil)
vc.view.superview?.frame = CGRectMake(0, 0, 200, 255)
vc.view.superview?.center = self.view.center
vc.view.layer.cornerRadius = 5
vc.view.layer.masksToBounds = true
此代码的问题是我的视图框以全屏模式打开,而不是以设置尺寸(200x255)打开。
我该如何解决这个问题?