Small instance of iOS development--uiimagepickercontroller

Source: Internet
Author: User

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

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.