[英]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.
}
} }
Create a NSTimer
that gets started when you present the image picker. 创建一个
NSTimer
,当您显示图像选择器时即可开始使用。 Set your desired waiting time. 设置所需的等待时间。
Then, in timer fire method dismiss the image picker. 然后,在计时器启动方法中关闭图像选择器。
If user dismisses the image picker before the timer fires, invalidate the timer in didFinishPickingMediaWithInfo
如果用户在计时器触发之前解雇了图像选择器,请在
didFinishPickingMediaWithInfo
计时器无效
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.