//: A UIKit based Playground for presenting user interface
import UIKit
import ARKit
import PlaygroundSupport
class MyViewController : UIViewController {
var discoverPanel : UIScrollView!
var ARPanel: UIView!
var ARViewer : ARSCNView!
var helpPanel : UIScrollView!
override func loadView() {
let names = ["Angel Shark", "Humpback Whale", "Great White Shark", "Bottlenose Dolphin", "Killer Whale", "Goliath Grouper"]
// add an empty panel to the view controller
let view = UIView()
view.backgroundColor = .white
makeTabBarButtons()
// initialize panels
discoverPanel = UIScrollView(frame: CGRect(x: 0, y: 400, width: 100, height: 100))
ARPanel = UIView(frame: CGRect(x: 150, y: 400, width: 100, height: 100))
helpPanel = UIScrollView(frame: CGRect(x: 300, y: 400, width: 100, height: 100))
// set background colors of each panel
discoverPanel.backgroundColor = .blue
ARPanel.backgroundColor = .red
helpPanel.backgroundColor = .orange
view.addSubview(discoverPanel)
view.addSubview(ARPanel)
view.addSubview(helpPanel)
self.view = view
}
func makeTabBarButtons()
{
/* Makes all of the tab bar buttons */
let discoverButton = UIButton(frame: CGRect(x: 0, y: 0, width: 40, height: 40))
let ARButton = UIButton(frame: CGRect(x: 150, y: 0, width: 40, height: 40))
let helpButton = UIButton(frame: CGRect(x: 300, y: 0, width: 40, height: 40))
/* Make all the tab bar buttons */
let discoverIconURLString = "https://lh3.googleusercontent.com/KPBfI_GChcO22uMUFBwjGg0aO1iXqUIOVcmoKPgs37rYH2RqdeM3ESnJX7Gr3s2cveqT4qwpjvBrS2pWl0mozikD5Vi268T9F13yCxh6YbbjOlZF8SgheOn_ujl5XDSonaiNLo435m7celkQ_kBlkXXSPqMPONu2ZUVb_LSFwLf9YxUPfFw-ShTzJGl2lWdUMPpA2qHfAIbhbrSkPa3-8-w38D1lKR5z2NNOte6S6NuWsapgRQyR21noHgzXIyXOKquPrVmn9PCwz938MBuH4x09zQqi5x_1HOHhccMvMReg7OGN1UBP87NpF7ALEyYQtHxZYyMSdw9bw9jbV69p9ucpP3zA3kviDEcjI3RIGkcGG47UnGoAS53TqJkg0wSyQUuiyfaaecaXg1kg8y85otINHYOwjVbQlyAfjsbF_athtqAw7xuT7b4OO9Ia4I3JVIRUuKt3GvDjPBUXnXYsqTYkxkL2ENNkTKBbfXxeqZlc8Bhkx47n-GNSHIqZ-gb0Zz44gwcPfm-FQ4mZ1Zk7FNx7f5W4oFXgea-rhXC5DqPjPNw4IIY7WmSI33S9tADc6MMbgBwndxFvk21aS3HC6y7LSOQbRcYff_-G-w17PtcPXrucubGjAzbqlqdYtDz-yOEOgUxwuHVh1ahI278x0Ax8YLmmKKQ=s512-no"
let discoverIconURL = URL(string: discoverIconURLString)!
let discoverIconData = try! Data(contentsOf: discoverIconURL)
let discoverIcon = UIImage(data: discoverIconData)
discoverButton.contentMode = .scaleAspectFit
discoverButton.setImage(discoverIcon, for: .normal)
let ARIconURLString = "https://lh3.googleusercontent.com/emT3b9yhU2o-uz-ZOoomqucgSvylLeWOKYKWbz88tP9zWJSzmIKiADxTWtxD39OiCO_aitwvhIzQ8ICmFbjSuZPTAgvgIEADjN3eft3IQewMVNNLsiKlYPQqnIzAvtn98Do5tBkAcNcY0Li1mX01UQmYyGBx8jF9oCytWirOxOwU68cF00oioqb1x-PVddQiMwcKf1UYtsqSUVXGvwK4G2KkSWOgvXYiH243bzt9PdVvDmz6rVsKqqTUTJewsKyyQf77xF772T8E_tkGQx0g-h8xgKhBhWJI21Zr2v1Z6A_c5xY7arR2ltA-m_yV30afoPm1wCz4dosnqNs7VqCdt2VnhMLhjc-NdFeVYG6b1LAmMDyZOFkTw_xrmnh-Z416ffolEtcZMjuNzEbHwBFwFDsmpMJj-R4SKXrRxtgBrYwRCpG1G3icgI_0G-Kj_rHIHrw4nMfHb708X5_K1SKIyeL5LIThfnxk5JOuS11vX680nFMRu9kmzrP3IdFoJT-6JLYPHtuTgS0kXfcoN7F3QSKd6E2Fl-X8uOxNRSbl9lvKk0I7ymChF5XFHJh5Q1zWCFxczDf8gEdQ1gKGJn4IrzISSwGqw51U2BgGQ6t5qV26CYIoRVeG1tZYUPBdtOdwrOPXgoP6oZDlemcfuJhxJxC4qAV8CSA=s512-no"
let ARIconURL = URL(string: ARIconURLString)!
let ARIconData = try! Data(contentsOf: ARIconURL)
let ARIcon = UIImage(data: ARIconData)
ARButton.contentMode = .scaleAspectFit
ARButton.setImage(ARIcon, for: .normal)
let helpIconURLString = "https://lh3.googleusercontent.com/2KWPU544EUiAK-RvZ86p3H9zMqTBqjaBCb_9Qs7ikq6sMxc_741GRddtnIQFksvOLgNbZtB3QMGIu-A-vhk5KY4U5MVKz0nzwvSh_k8bxndghZt-pcycL6nTxrXgdQmsgY-Lcm2y_5ju1CRLUsnfJXPPWv4jNN2JicB4Vx4kxzjyvbmSS7KKIFy3v2TcVpUKYOyvOtPtTftOavph9mIYU7pJIc1_ihjl9KHbuUCpk0OSrgvXgqKq_zLWcFq8TEkI7ryMGytds92HTDEDQ9dWEesIgdWk4lIH-aKkJIiLLRc-qj4SRygc4Lbl5RCELfnhDngbuen2LCS7PS8g2bu3Qsp_9asAW2AImECZ6EoXHSH7mBUHc8cVkG52YKjwqIfOIaGhPN1aO6EcSlHnsyEpH_XpVb10IvDE0q48gx8bCu1OnX91q5tHyCnIyxGDny28VbLDTaoIF2pg6s9YA-opPOLWMwNGg0Hel2I4ZA45iSH7-NICRB4Cg7Ym4Alk3-CB94HETdZv5fUkRCwCMZUYIdyB0-ZhqiruQ1XDN7z01jl0mWnP6gsAQhwHovTivjz-m3LE1_gcvB_KOGWYAlE7L7SPQ1x996ea1PNaP4q8aNXPHKMToKw4xnACqTY6zSSv4l-MBw40g5Wq-URz1vYoG2QPVHTc0HY=s512-no"
let helpIconURL = URL(string: helpIconURLString)!
let helpIconData = try! Data(contentsOf: helpIconURL)
let helpIcon = UIImage(data: helpIconData)
helpButton.contentMode = .scaleAspectFit
helpButton.setImage(helpIcon, for: .normal)
view.addSubview(discoverButton)
view.addSubview(ARButton)
view.addSubview(helpButton)
}
}
// Present the view controller in the Live View window
PlaygroundPage.current.liveView = MyViewController()
iPad上的Swits Playgrounds不适用于此代码。我尝试过重新保存文件并制作文件副本,但没有收到任何错误。相反,当我在不通知我的情况下运行代码时,iPad崩溃了。我不知道为什么,因为几乎完全相同的代码在几个小时前就可以完美工作。
最佳答案
您在makeTabBarButtons()
内调用loadView
makeTabBarButtons()
尝试在self.view
中添加3个尚未加载的按钮,因此loadView
被称为
递归发生,很可能导致堆栈溢出,因此应用程序在运行时崩溃
您可以通过将makeTabBarButtons()
声明更改为:func makeTabBarButtons(in view: UIView)
并将其命名为:makeTabBarButtons(in: view)
来修复它。
这样,您将中断通话周期。