IOS development-album picker UIImagePickerController

Source: Internet
Author: User

Uiimagepickercontroller Overview:

The uiimagepickercontroller class is a user interface for obtaining selected images and videos. We can use this controller to select the images and videos we need. This class is special. We cannot customize it at will, nor inherit the subclass generated.

When we use the uiimagepickercontroller class, we only need to call the code to display and start the position of it. Of course, we can then select the desired image and video, alternatively, you can click Cancel.

But before we call the interface, we need to confirm:

I. Whether the current device supports using uiimagepickercontroller. In this case, we need to call issourcetypeavailable: method to determine whether to use uiimagepickercontroller.

2. view the media type (image or video). At this time, we call availablemediatypesforsourcetype:
Method judgment.

When using uiimagepickercontroller at the same time, we need the uiimagepickercontrollerdelegate protocol proxy to implement certain time-specific actions. We can choose to use the flashlight when calling the camera, but there is a 10-minute limit on the video by default. You need to use the videomaximumduration attribute to change the default time,

3. Set the media attributes on the UI.

1: sourcetype // from which media is selected
Enum {
Uiimagepickercontrollersourcetypephotolibrary,
Uiimagepickercontrollersourcetypecamera,
Uiimagepickercontrollersourcetypesavedphotosalbum
};
Typedef NSUInteger UIImagePickerControllerSourceType;

2: mediaTypes
MediaTypes is used to determine which types of multimedia files and images are displayed in picker? Video?
+ (NSArray *) availableMediaTypesForSourceType :( UIImagePickerControllerSourceType) sourceType

There are three optional proxy Methods: UIImagePickerControllerDelegate
-ImagePickerController: didFinishPickingMediaWithInfo:
-ImagePickerControllerDidCancel:
-ImagePickerController: didFinishPickingImage: editingInfo:


-(Void) pick {
[ImagePicker takePicture];
}

-(IBAction) press :( id) sender {
ImagePicker = [UIImagePickerController alloc] init];
ImagePicker. delegate = self;
ImagePicker. mediaTypes = [UIImagePickerController availableMediaTypesForSourceType: UIImagePickerControllerSourceTypeCamera];
ImagePicker. sourceType = UIImagePickerControllerSourceTypeCamera;
ImagePicker. showsCameraControls = NO;

UIView * view = [UIView alloc] initWithFrame: CGRectMake (0, 0,320, 44)];
View. backgroundColor = [UIColor redColor];
UIButton * button = [UIButton alloc] initWithFrame: CGRectMake (0, 0, 40, 40)];
Button. backgroundColor = [UIColor blueColor];
[Button addTarget: self action: @ selector (pick) forControlEvents: UIControlEventTouchUpInside];
[View addSubview: button];

CGRect newFrame = CGRectMake (0.0, 436,320, 44 );
View. frame = newFrame;
ImagePicker. cameraOverlayView = view;
[Self presentModalViewController: imagePicker animated: YES];
}


-(Void) imagePickerController :( UIImagePickerController *) picker didFinishPickingMediaWithInfo :( NSDictionary *) info
{
If ([info objectforkey: uiimagepickercontrollermediatype] isw.tostring :( nsstring *) kuttypeimage]) {
Uiimage * image = [info objectforkey: uiimagepickercontrolleroriginalimage];
Uiimagewritetosavedphotosalbum (image, self, @ selector (image: didfinishsavingwitherror: contextinfo :), nil );

Related Article

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.