ios - 在 Obj-C ViewController 上打开 Swift ViewController
问题描述
我有一个 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 视图之间的手势行为!
当我想在上述视图的某个点上显示一个弹出窗口 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)
谢谢!
解决方案
推荐阅读
- java - PowerMock expectNew 不会返回模拟实例
- python - Python 模块应该如何使用代码生成?
- javascript - 如何使用JavaScript单击删除和添加css动画属性
- python-3.x - 如何在文件中找到前五个结果的总和
- php - 使用 TCPDF 将多个具有透明度的图像分层
- python - 从子包运行 Python 测试
- liferay-7 - Liferay 7.2 Finder 不满意的参考资料
- php - 在 phpunit 测试中呈现树枝模板的问题
- javascript - Want client-side Firebase logs to show up in StackDriver, not users' browsers
- c# - 如何在设置中使用字符串文件路径,以便我可以在我的代码中使用该路径