Excerpt from: http://www.cnblogs.com/goodboy-heyang/p/5403947.html
Preface: This post is I read foreign iOS programming tutorial an introductory article of the learning process summary, difficult, because is the introduction. Basically is the introduction Uiimagepickercontroller this controller, then this controller is why? is to invoke the device camera function. You may need to test on a real machine in the back, because the iphone simulator can't support the camera function, and running tests will crash.
Website: http://www.appcoda.com/ios-programming-camera-iphone-app/
1, the first simple to create a project, and then in the storyboard and corresponding. m file to add the relevant code, this concise tutorial does not use automatic layout, not to say, look at the picture literacy:
2, the following is the complete implementation of this VIEWCONTROLLER.M:
#import "ViewController.h"@interfaceViewcontroller () <UIImagePickerControllerDelegate,UINavigationControllerDelegate>@property (Strong, nonatomic) Iboutlet Uiimageview*ImageView;@end@implementationViewcontroller- (void) viewdidload {[Super viewdidload]; //This code will automatically determine whether the current device has a camera function, if not, will pop-up window prompt if(![Uiimagepickercontroller Issourcetypeavailable:uiimagepickercontrollersourcetypecamera]) {Uialertview*myalertview = [[Uialertview alloc] Initwithtitle:@"Error"message:@"Device has no camera" Delegate: nil Cancelbuttontitle:@"OK"Otherbuttontitles:nil]; [Myalertview show]; }}-(Ibaction) Takephotot: (UIButton *) Sender {//To Create a Uiimagepickercontroller controller objectUiimagepickercontroller *picker =[[Uiimagepickercontroller alloc] init]; Picker.Delegate=Self ; Picker.allowsediting=YES; Picker.sourcetype=Uiimagepickercontrollersourcetypecamera; [Self Presentviewcontroller:picker animated:yes completion:nil];}-(Ibaction) Selectphoto: (UIButton *) Sender {//To Create a Uiimagepickercontroller controller objectUiimagepickercontroller *picker =[[Uiimagepickercontroller alloc] init]; Picker.Delegate=Self ; Picker.allowsediting=YES; Picker.sourcetype=uiimagepickercontrollersourcetypephotolibrary; [Self Presentviewcontroller:picker animated:yes completion:nil];}#pragmaMark-Proxy Method-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (NSDictionary<NSString *,ID> *) info{UIImage* Chosenimage =Info[uiimagepickercontrollereditedimage]; Self.imageView.image=Chosenimage; [Picker Dismissviewcontrolleranimated:yes completion:nil];}-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker{[picker Dismissviewcontrolleranimated:yes completion:nil];}@end
Small instance of iOS development--uiimagepickercontroller