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 );