我试图在我的快速应用程序中实现一些简单的屏幕镜像,但我得到了不受欢迎的行为。当我的代码执行时,外部显示器获取电话视图但iphone屏幕变黑。在外部视图中,它也用黑色填充。这是一个截图:
这是我设置外部视图的代码:
func initializeExternalScreen(external: UIScreen){
self.mirroredScreen = external;
// Find max resolution
var max = CGSize()
var maxScreenMode = UIScreenMode()
for current in self.mirroredScreen.availableModes {
if (current.size.height > max.height || current.size.width > max.width) {
max = current.size;
maxScreenMode = current;
}
}
self.mirroredScreen.currentMode = maxScreenMode;
self.mirroredWindow = UIWindow(frame: self.mirroredScreen.bounds)
self.mirroredWindow.hidden = false
self.mirroredWindow.layer.contentsGravity = kCAGravityResizeAspect
self.mirroredWindow.screen = self.mirroredScreen
self.mirroredScreenView = UIView(frame: self.mirroredScreen.bounds)
self.mirroredScreenView.addSubview(self.view)
self.mirroredWindow.addSubview(self.mirroredScreenView)
}
有什么想法吗?