Создание полноэкранного отображения моей камеры на iPadIOS

Программируем под IOS
Ответить
Anonymous
 Создание полноэкранного отображения моей камеры на iPad

Сообщение Anonymous »

Я использую код, созданный https://medium.com/@barbulescualex/maki ... 44e3087563. Я возился с этим, чтобы отобразить вид камеры и показать ландшафт. Однако я не знаю, как получить полный экран и заполнить черные области выше и ниже. Скриншот < /p>
Это файл 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()
}
}
Я новичок в разработке Swift, поэтому мне бы очень понравилась любая помощь :)
Я попытался использовать modalpresentationstyle = .overfullscreen, но это не внесло никаких изменений.>

Подробнее здесь: https://stackoverflow.com/questions/797 ... en-on-ipad
Ответить

Быстрый ответ

Изменение регистра текста: 
Смайлики
:) :( :oops: :roll: :wink: :muza: :clever: :sorry: :angel: :read: *x)
Ещё смайлики…
   
К этому ответу прикреплено по крайней мере одно вложение.

Если вы не хотите добавлять вложения, оставьте поля пустыми.

Максимально разрешённый размер вложения: 15 МБ.

Вернуться в «IOS»