我有一个Swift项目,并且我通过以下方式将Obj-C ViewController附加到其视图中:
+ (void)attachGameController:(UIViewController *)view
{
GameViewController *c = [GameViewController numberTile:4 backgroundColor:[UIColor whiteColor] buttonControls:NO swipeControls:YES];
[view addChildViewController:c];
[view.view addSubview:c.view];
[c didMoveToParentViewController:view];
// configure the view
c.view.translatesAutoresizingMaskIntoConstraints = NO;
[c.view.topAnchor constraintEqualToAnchor:view.view.topAnchor].active = YES;
[c.view.leftAnchor constraintEqualToAnchor:view.view.leftAnchor].active = YES;
[c.view.widthAnchor constraintEqualToAnchor:view.view.widthAnchor].active = YES;
[c.view.heightAnchor constraintEqualToAnchor:view.view.heightAnchor].active = YES;
}
// from Swift ViewController I'm calling the above method as
attachGameController(self)
这很有效,包括Swift和Obj-C视图之间的手势行为!
当我想在上面的视图中的某个点上显示一个popover Swift ViewController时,问题就开始了。我尝试了以下但是都无法打开ViewController而且没有错误:
let help = HelpUserController()
self.presentingViewController?.present(help, animated: false, completion: nil)
// or
self.present(help, animated: false, completion: nil)
// or
help.view.frame = self.view.frame
self.addChildViewController(help)
self.view.addSubview(help.view)
help.didMove(toParentViewController: self)
谢谢!