2016-03-05 39 views
2

所以我在初始控制視圖中有一個按鈕,將用戶帶到相機界面。用戶在拍攝照片後返回到初始視圖控制器,但如果用戶未拍攝照片,如何關閉相機並在特定時間段後返回到初始頁面或其他頁面。如何在swift2中的xcode上關閉相機界面並打開不同的視圖控制器?

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. 
} 

}

回答

0
  1. 創建,當你出現在圖像拾取是被開始NSTimer。設置你想要的等待時間。

  2. 然後,在定時器消防方法中關閉圖像選擇器。

  3. 如果用戶關閉計時器觸發之前的圖像選擇器,在didFinishPickingMediaWithInfo

無效定時器
相關問題