HomeiOS Developmentios - Making my digital camera show full display screen on iPad

ios – Making my digital camera show full display screen on iPad


I am utilizing the code created by https://medium.com/@barbulescualex/making-a-custom-camera-in-ios-ea44e3087563. I’ve tinkered with it to solely show the digital camera view and present panorama. Nonetheless I do not know how one can get it go full display screen and replenish the black areas above and under. Screenshot

That is the SceneDelegate.swift file:

class SceneDelegate: UIResponder, UIWindowSceneDelegate {
    var window: UIWindow?
    
    func scene(_ scene: UIScene, willConnectTo session: UISceneSession, choices       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()
        
    }
}

That is the ViewController setupView()

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, motion: #selector(switchCamera(_:)), for: .touchUpInside)
    }

MTKViewDelegate code with logged print outputs (see “This prints…”)

extension ViewController : MTKViewDelegate {
    func mtkView(_ view: MTKView, drawableSizeWillChange measurement: CGSize) {
        //tells us the drawable's measurement has modified
        //NSLog("MTKView drawable measurement will change to (measurement)")
    }
    
    func draw(in view: MTKView) {
        //create command buffer for ciContext to make use of to encode it is rendering directions to our GPU
        guard let commandBuffer = metalCommandQueue.makeCommandBuffer() else {
            return
        }
        
        //be sure that we even have a ciImage to work with
        guard var ciImage = currentCIImage else {
            return
        }
        
        //be sure that the present drawable object for this metallic view is offered (it is not in use by the earlier draw cycle)
        guard let currentDrawable = view.currentDrawable else {
            return
        }
        
        print(ciImage.extent.width) # This prints 2430.0
        print(ciImage.extent.peak) # This prints 1830.0
        print(view.drawableSize) # This prints (1688.0, 780.0)

        //be sure that body is centered on display screen
        let heightOfciImage = ciImage.extent.peak
        let heightOfDrawable = view.drawableSize.peak
        let yOffsetFromBottom = (heightOfDrawable - heightOfciImage)/2
        
        //render into the metallic texture
        self.ciContext.render(ciImage,
                              to: currentDrawable.texture,
                   commandBuffer: commandBuffer,
                          bounds: CGRect(origin: CGPoint(x: 0, y: -yOffsetFromBottom), measurement: view.drawableSize),
                      colorSpace: CGColorSpaceCreateDeviceRGB())
        
        //register the place to attract the directions within the command buffer as soon as it executes
        commandBuffer.current(currentDrawable)
        //commit the command to the queue so it executes
        commandBuffer.commit()
    }
}

I am new to Swift growth so I might love any assist 🙂

I’ve tried utilizing modalPresentationStyle = .overFullScreen however that did not make any modifications.

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

- Advertisment -
Google search engine

Most Popular

Recent Comments