Это файл scenedelegate.swift: < /p>
Код: Выделить всё
class SceneDelegate: UIResponder, UIWindowSceneDelegate {
var window: UIWindow?
func scene(_ scene: UIScene, willConnectTo session: UISceneSession, options connectionOptions: UIScene.ConnectionOptions) {
guard let windowScene = (scene as? UIWindowScene) else { return }
window = UIWindow(windowScene: windowScene)
let rootVC = ViewController()
rootVC.modalPresentationStyle = .overFullScreen
window?.rootViewController = rootVC
window?.makeKeyAndVisible()
}
}
< /code>
Это ViewController setupview () < /p>
extension ViewController {
//MARK:- View Setup
func setupView(){
view.backgroundColor = .purple
mtkView.translatesAutoresizingMaskIntoConstraints = false
view.addSubview(mtkView)
view.addSubview(switchCameraButton)
NSLayoutConstraint.activate([
switchCameraButton.widthAnchor.constraint(equalToConstant: 30),
switchCameraButton.heightAnchor.constraint(equalToConstant: 30),
switchCameraButton.topAnchor.constraint(equalTo: view.safeAreaLayoutGuide.topAnchor, constant: 10),
switchCameraButton.trailingAnchor.constraint(equalTo: view.safeAreaLayoutGuide.trailingAnchor, constant: -10),
mtkView.bottomAnchor.constraint(equalTo: view.bottomAnchor),
mtkView.trailingAnchor.constraint(equalTo: view.trailingAnchor),
mtkView.leadingAnchor.constraint(equalTo: view.leadingAnchor),
mtkView.topAnchor.constraint(equalTo: view.topAnchor)
])
switchCameraButton.addTarget(self, action: #selector(switchCamera(_:)), for: .touchUpInside)
}
< /code>
mtkviewdelegate код с зарегистрированными выходами печати (см. «Это печати ...») < /p>
extension ViewController : MTKViewDelegate {
func mtkView(_ view: MTKView, drawableSizeWillChange size: CGSize) {
//tells us the drawable's size has changed
//NSLog("MTKView drawable size will change to \(size)")
}
func draw(in view: MTKView) {
//create command buffer for ciContext to use to encode it's rendering instructions to our GPU
guard let commandBuffer = metalCommandQueue.makeCommandBuffer() else {
return
}
//make sure we actually have a ciImage to work with
guard var ciImage = currentCIImage else {
return
}
//make sure the current drawable object for this metal view is available (it's not in use by the previous draw cycle)
guard let currentDrawable = view.currentDrawable else {
return
}
print(ciImage.extent.width) # This prints 2430.0
print(ciImage.extent.height) # This prints 1830.0
print(view.drawableSize) # This prints (1688.0, 780.0)
//make sure frame is centered on screen
let heightOfciImage = ciImage.extent.height
let heightOfDrawable = view.drawableSize.height
let yOffsetFromBottom = (heightOfDrawable - heightOfciImage)/2
//render into the metal texture
self.ciContext.render(ciImage,
to: currentDrawable.texture,
commandBuffer: commandBuffer,
bounds: CGRect(origin: CGPoint(x: 0, y: -yOffsetFromBottom), size: view.drawableSize),
colorSpace: CGColorSpaceCreateDeviceRGB())
//register where to draw the instructions in the command buffer once it executes
commandBuffer.present(currentDrawable)
//commit the command to the queue so it executes
commandBuffer.commit()
}
}
Я попытался использовать modalpresentationstyle = .overfullscreen, но это не внесло никаких изменений.>
Подробнее здесь: https://stackoverflow.com/questions/797 ... en-on-ipad
Мобильная версия