简体   繁体   English

经过一定时间后,如何在swift2中的xcode上关闭相机界面并打开其他视图控制器?

[英]How do I close the camera interface after a certain time on xcode in swift2 and open a different view controller?

So I have a button in the initial control view which takes the user to the camera interface. 因此,我在初始控制视图中有一个按钮,可将用户带到摄像头界面。 The user goes back to the initial view controller after taking a photo but how do I make the app close the camera and return to the initial page or a different page after a certain time period if the user doesn't take a picture. 用户拍照后返回初始视图控制器,但是如果用户不拍照,如何在一定时间后关闭相机并返回到初始页面或其他页面。

import UIKit

class ViewController: UIViewController, UIImagePickerControllerDelegate, UINavigationControllerDelegate {


@IBOutlet weak var CameraButton: UIButton!

@IBOutlet weak var photoLibrary: UIButton!

@IBOutlet weak var imageView: UIImageView!


@IBAction func cameraAction(sender: UIButton) {

    let picker = UIImagePickerController()
    picker.delegate = self
    picker.sourceType = .Camera

    presentViewController(picker, animated: true, completion: nil)

}


@IBAction func photoLibraryAction(sender: AnyObject) {

    let picker = UIImagePickerController()
    picker.delegate = self
    picker.sourceType = .PhotoLibrary

    presentViewController(picker, animated: true, completion: nil)
}


func imagePickerController(picker: UIImagePickerController, didFinishPickingMediaWithInfo info: [String : AnyObject]) {
    imageView.image = info [UIImagePickerControllerOriginalImage] as? UIImage;
    dismissViewControllerAnimated(true, completion: nil)
}




override func viewDidLoad() {
    super.viewDidLoad()
    // Do any additional setup after loading the view, typically from a nib.
}

override func didReceiveMemoryWarning() {
    super.didReceiveMemoryWarning()
    // Dispose of any resources that can be recreated.
}

} }

  1. Create a NSTimer that gets started when you present the image picker. 创建一个NSTimer ,当您显示图像选择器时即可开始使用。 Set your desired waiting time. 设置所需的等待时间。

  2. Then, in timer fire method dismiss the image picker. 然后,在计时器启动方法中关闭图像选择器。

  3. If user dismisses the image picker before the timer fires, invalidate the timer in didFinishPickingMediaWithInfo 如果用户在计时器触发之前解雇了图像选择器,请在didFinishPickingMediaWithInfo计时器无效

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 允许一个视图控制器在swift2 xcode7中旋转景观 - Allow one view controller to rotate landscape in swift2 xcode7 如何在swift2的本地目录中打开txt文件? - How can I open a txt file in local directory in swift2? 在 Xcode 中执行 segue 后如何关闭视图控制器? - How to close a View Controller after Performing segue in Xcode? 如何在Xcode Interface Builder中向表视图控制器(带有静态单元格)添加导航项? - How do I add a navigation item to a Table View Controller (with static cells) in Xcode Interface Builder? 如何关闭我用“替换”按钮打开的视图控制器 - how to close the view controller that I open with “replace” segue 如何检查视图控制器是否为初始视图控制器? (SWIFT 3) - How do I check if view controller is initial view controller? (SWIFT 3) 如何在swift2中将分钟添加到自定义时间 - How to add minutes to custom time in swift2 当LoginView是初始视图时,在情节提要中子类化UITabBarController [Swift2,Xcode 7] - Subclassing UITabBarController in storyboard when LoginView is initial view [Swift2, Xcode 7] 在快速的iOS 8中,当单击一个单元格时,如何获取它以打开另一个视图控制器? - In swift iOS 8 when a cell is clicked, how do I get it to open another view controller? UITabBarController子视图控制器重置-Swift2 iOS - UITabBarController child view controller reset -Swift2 iOS
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM