gpt4 book ai didi

ios - 在我的 iPhone 上运行程序时看不到我的按钮

转载 作者:行者123 更新时间:2023-11-28 19:30:32 27 4
gpt4 key购买 nike

为什么我在运行我的程序时看不到我的按钮,但在 Xcode 8 中我可以看到它。它位于一个 View 之上,看起来就像您在 snapchat 中用来拍照的按钮。

我是 Xcode 和 swift 的新手,所以如果我需要了解 Xcode 或 Storyboard 可以帮助我解决这些问题的任何信息,请告诉我。 enter image description here

View 代码:

 import UIKit
import AVFoundation
import QuartzCore

class View1: UIViewController , AVCaptureVideoDataOutputSampleBufferDelegate{

let captureSession = AVCaptureSession()

var previewLayer: CALayer!

var captureDevice: AVCaptureDevice!


@IBOutlet weak var cameraView: UIView!

override func viewDidLoad() {
super.viewDidLoad()


}


/*



This is a function to prepair the camera

and check that there is a camera.



If there isn't a camera on the device

then get you will get a error.



*/

func prepareCamera()

{



captureSession.sessionPreset = AVCaptureSessionPreset1920x1080





if let availableDevices = AVCaptureDeviceDiscoverySession(deviceTypes: [.builtInWideAngleCamera],
mediaType: AVMediaTypeVideo,
position: .back).devices

{



captureDevice = availableDevices.first

beginSession()



}





}



func beginSession()

{



do

{



let captureDeviceInput = try AVCaptureDeviceInput(device: captureDevice)

captureSession.addInput(captureDeviceInput)



}

catch

{



print(error.localizedDescription)

/*



Figure out what to do here

*/

}



if let previewLayer = AVCaptureVideoPreviewLayer(session: captureSession)

{



self.previewLayer = previewLayer

self.view.layer.addSublayer(
self.previewLayer)

self.previewLayer.frame = self.view.layer.frame

self.previewLayer.frame.size = self.view.layer.frame.size

captureSession.startRunning()



let dataOutput = AVCaptureVideoDataOutput()

dataOutput.videoSettings = [(kCVPixelBufferPixelFormatTypeKey as NSString
): NSNumber(value: kCVPixelFormatType_32BGRA)]


dataOutput.alwaysDiscardsLateVideoFrames = true


if captureSession.canAddOutput(dataOutput)

{

captureSession.addOutput(dataOutput)


}

captureSession.commitConfiguration()

let queue = DispatchQueue(label: "com.PhotoAllergy.captureQueue")
dataOutput.setSampleBufferDelegate(self, queue: queue)



}









}



//func captureOutput(_ captureOutput: AVCaptureOutput!, didDrop sampleBuffer: CMSampleBuffer!, from connection: AVCaptureConnection!) {
//yeeye
//}

override func viewWillAppear(_ animated: Bool) {

super.viewWillAppear(animated)

prepareCamera()

}








override func didReceiveMemoryWarning() {
super.didReceiveMemoryWarning()

}


}

最佳答案

添加约束。按照这些图片

enter image description here enter image description here

祝你好运,如果你对此有任何疑问,可以在这里发表评论。

关于ios - 在我的 iPhone 上运行程序时看不到我的按钮,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45322542/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com