我正在做一个ArKit+CoreLocation应用程序,当我触摸一个节点时,我会在屏幕上的视图上显示一些信息。问题是,当我旋转设备时,我重新绘制DataView,但绘制不正确。
我注意到的第一件事是,当我启动应用程序,手机处于纵向模式时,我必须对if(!UIDevice.current.orientation.isPortrait )进行评估,以获得正确的尺寸。为什么在发射过程中方向不是纵向的?
而且,只有在应用程序启动时才能很好地管理维度。如果我在横向模式下运行应用程序,视图将正确呈现,而纵向视图则是相同的情况。我检测到的另一个问题是,当我“重绘”视图时,如果我想更新视图中的文本,那是不可能的。
我制作了一个视频来告诉你发生了什么,也是为了知道当一个节点被选中时,它周围有一个紫色的圆圈。你会看到,在重新定位之后,无论我触摸哪个节点,我都无法更新文本。Y6dnW8E4
我的源代码是
/*
* Initialize the TextView to display the information about the monument
*/
func initDataView() {
let screenWidth = self.view.frame.width
let screenHeight = self.view.frame.height
var leftPadding : CGFloat = 0.0
var bottomPadding : CGFloat = 0.0
var frameHeight : CGFloat = 0.0
/*
* Configure paddings if the device is a phone
*/
if (UIDevice.current.userInterfaceIdiom == .phone) {
if ( UIDevice.current.orientation.isPortrait ) {
(leftPadding, bottomPadding, frameHeight) = getDataViewPaddings(phone: true, portrait: true, screenWidth: screenWidth, screenHeight: screenHeight)
} else {
(leftPadding, bottomPadding, frameHeight) = getDataViewPaddings(phone: true, portrait: false, screenWidth: screenWidth, screenHeight: screenHeight)
}
}
dataView = UIView(frame: CGRect(x: 0, y: 0, width: screenWidth-(leftPadding*2), height: screenHeight/frameHeight))
dataView.frame.origin.x = leftPadding
dataView.frame.origin.y = screenHeight - dataView.frame.height - bottomPadding
//dataView.backgroundColor = UIColor.white.withAlphaComponent(0.7)
//Adjust border and border color
dataView.layer.borderWidth = 4.0
dataView.layer.borderColor = UIColor(hexString: "#951789ff")?.cgColor
initTextView(leftPadding: leftPadding)
dataView.addSubview(textView)
dataView.addSubview(descriptionView)
dataView.addSubview(iconView)
}
public override func willTransition(to newCollection: UITraitCollection, with coordinator: UIViewControllerTransitionCoordinator) {
initDataView()
}发布于 2018-12-05 06:51:53
将UIKit UIViews与ARkit ARSCNView一起使用与任何其他视图没有什么不同。如果您正在设置自定义框架,则必须在viewDidLayoutSubviews中完成该代码。在这种情况下,它看起来就像你只想将你的视图与前缘和底部保持一定的距离,宽度和高度不变。如果这是您想要的,那么只需使用自动收费表,让布局引擎计算位置。这可以在代码或接口生成器中使用。您也可以在接口生成器中手动将UIView类设置为ARSCNView。
https://stackoverflow.com/questions/53623696
复制相似问题