首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >UIButton位置更改\ UIWindow \ ReplayKit

UIButton位置更改\ UIWindow \ ReplayKit
EN

Stack Overflow用户
提问于 2018-03-07 07:39:45
回答 1查看 266关注 0票数 1

我在和Replaykit合作录制屏幕..。使用以下代码将录像机UIButton排除在录音之外.效果很好。录制视频后,我将发出警告,并提供编辑或删除选项。当我选择编辑和取消时,我将得到我的主视图作为rootviewcontroller。

问题:在我取消两次之后..。按钮位置更改并设置为视图的左上角(buttonWindow)

代码:

代码语言:javascript
复制
 func addButtons( button1: UIButton) {
    self.buttonWindow = UIWindow(frame: self.view.frame)
    self.buttonWindow.rootViewController = HiddenStatusBarViewController()
    self.buttonWindow.rootViewController?.view.addSubview(button1)
    self.buttonWindow.rootViewController?.view.updateConstraintsIfNeeded()
    self.buttonWindow.makeKeyAndVisible()

}


override func viewDidLayoutSubviews() {
    print(3)
    self.videoBtn.frame = (CGRect(x: 155, y: 575, width: 65, height: 65))

}
    func startRecording() {

    DispatchQueue.main.async {
        // Update UI
        self.addButtons(button1: self.videoBtn)


    }


    self.videoBtn.setImage(UIImage(named:"video capture"), for: .normal)
    self.videoBtn.tintColor = .red

    guard recorder.isAvailable else {
        print("Recording is not available at this time.")
        self.videoBtn.tintColor = .white
        return
    }

    recorder.isMicrophoneEnabled = true


    recorder.startRecording{ [unowned self] (error) in

        guard error == nil else {
            print("There was an error starting the recording.")
            self.videoBtn.tintColor = .white
            return
        }

        print("Started Recording Successfully")

        self.isRecording = true

    }

}

func stopRecording() {

    self.videoBtn.tintColor = .white
    recorder.stopRecording { [unowned self] (preview, error) in
        print("Stopped recording")


        guard preview != nil else {
            print("Preview controller is not available.")
            return
        }

        let alert = UIAlertController(title: "Recording Finished", message: "Would you like to edit or delete your recording?", preferredStyle: .alert)

        let deleteAction = UIAlertAction(title: "Delete", style: .destructive, handler: { (action: UIAlertAction) in
            self.recorder.discardRecording(handler: { () -> Void in
                print("Recording suffessfully deleted.")

            })
        })

        let editAction = UIAlertAction(title: "Edit", style: .default, handler: { (action: UIAlertAction) -> Void in
            preview?.previewControllerDelegate = self.buttonWindow.rootViewController as? RPPreviewViewControllerDelegate
            self.buttonWindow.rootViewController?.present(preview!, animated: true, completion: nil)
        })

        alert.addAction(editAction)
        alert.addAction(deleteAction)
        self.buttonWindow.rootViewController?.present(alert, animated: true, completion: nil)

        self.isRecording = false

        let storyboard = UIStoryboard(name: "Main", bundle: nil)
        let rootController = storyboard.instantiateViewController(withIdentifier: "ViewController")


        let app = UIApplication.shared
        app.keyWindow?.rootViewController = rootController

    }
    DispatchQueue.main.async {
        // Update UI
       }

}

func previewControllerDidFinish(_ previewController: RPPreviewViewController) {
    dismiss(animated: true)
}

谢谢:)

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2018-03-08 08:59:36

我通过取消自动收费表解决了这个问题!那个可以。谢谢!

如果你想用自动布局的话?那么下面的代码就可以了!

代码语言:javascript
复制
self.buttonWindow.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutAttribute.centerX, relatedBy: NSLayoutRelation.equal, toItem: self.buttonWindow, attribute: NSLayoutAttribute.centerX, multiplier: 1, constant: 0))

self.buttonWindow.addConstraint(NSLayoutConstraint(item: button1, attribute: NSLayoutAttribute.bottom, relatedBy: NSLayoutRelation.equal, toItem: self.buttonWindow, attribute: NSLayoutAttribute.bottom, multiplier: 1, constant: -50))
票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49146537

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档