代码创建的ARSCNView打开时比storyboard慢
ARSCNView created by code is slower than storyboard when opening
我尝试使用代码在 viewDidLoad 中创建 ARSCNView,如下所示:
_sceneView = [[ARSCNView alloc] initWithFrame:self.view.bounds];
_sceneView.automaticallyUpdatesLighting = YES;
[self.view addSubview:_sceneView];
ARWorldTrackingConfiguration *configuration = [ARWorldTrackingConfiguration new];
configuration.worldAlignment = ARWorldAlignmentGravityAndHeading;
configuration.lightEstimationEnabled = YES;
[_sceneView.session runWithConfiguration:configuration];
然后我用代码打开它:
MyARViewController *vc = [[MyARViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
我能明显感觉到刚开始有点卡顿,然后就正常了,用storyboard创建ARSCNView,打开view很流畅
可能是什么导致了这个问题?
我认为问题出在您添加 ARSCNView
的方式上。
当您使用StoryBoard
添加ARSCNView
时,将调用ARSCNView
的initWithCoder
方法而不是initWithFrame
。我猜你在 initWithFrame
中做了一些事情而你在 initWithCoder
.
中没有做任何事情
这就是为什么以编程方式添加 ARSCNView
和从 StoryBoard
添加之间存在差异
更新
另一个问题是您在使用 StoryBoard
时创建 MyARViewController
的方式。 MyARViewController *vc = [[MyARViewController alloc] init];
不是从 StoryBoard 创建 MyARViewController
的正确方法。 ARSCNView
无法添加到 MyARViewController
。这就是为什么你不喂卡住。
我尝试使用代码在 viewDidLoad 中创建 ARSCNView,如下所示:
_sceneView = [[ARSCNView alloc] initWithFrame:self.view.bounds];
_sceneView.automaticallyUpdatesLighting = YES;
[self.view addSubview:_sceneView];
ARWorldTrackingConfiguration *configuration = [ARWorldTrackingConfiguration new];
configuration.worldAlignment = ARWorldAlignmentGravityAndHeading;
configuration.lightEstimationEnabled = YES;
[_sceneView.session runWithConfiguration:configuration];
然后我用代码打开它:
MyARViewController *vc = [[MyARViewController alloc] init];
[self.navigationController pushViewController:vc animated:YES];
我能明显感觉到刚开始有点卡顿,然后就正常了,用storyboard创建ARSCNView,打开view很流畅
可能是什么导致了这个问题?
我认为问题出在您添加 ARSCNView
的方式上。
当您使用StoryBoard
添加ARSCNView
时,将调用ARSCNView
的initWithCoder
方法而不是initWithFrame
。我猜你在 initWithFrame
中做了一些事情而你在 initWithCoder
.
这就是为什么以编程方式添加 ARSCNView
和从 StoryBoard
更新
另一个问题是您在使用 StoryBoard
时创建 MyARViewController
的方式。 MyARViewController *vc = [[MyARViewController alloc] init];
不是从 StoryBoard 创建 MyARViewController
的正确方法。 ARSCNView
无法添加到 MyARViewController
。这就是为什么你不喂卡住。