我在iPhone上运行程序时无法看到我的按钮

时间:2017-07-26 09:16:00

标签: ios iphone autolayout storyboard

为什么我在运行程序时看不到我的按钮,但在Xcode 8中我可以看到它。这是一个视图,看起来像你按下按钮在Snapchat中拍照。

我是Xcode和swift的新手,所以如果我需要知道Xcode或故事板可以帮助我解决这些问题,请告诉我。 enter image description here

视图的代码:

 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()

}


 }

2 个答案:

答案 0 :(得分:2)

添加约束。 请关注这些图片

enter image description here enter image description here

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

答案 1 :(得分:1)

执行以下操作

在情节提要视图控制器中选择您的按钮,然后按照屏幕截图中的步骤操作 按下按钮添加约束 运行应用程序

enter image description here

请将viewController作为初始视图控制器,如下图所示

enter image description here