IOS camera call
Two proxies are required to call the camera.
UIImagePickerControllerDelegate, UINavigationControllerDelegate
Otherwise:
When delegate is set, a warning is displayed: Assigning to 'id 'From incompatible type 'addsightingviewcontroller * const _ strong'
Solution Process]
1. The problem is obvious that strong is incompatible. Then, try and change the corresponding AddSightingViewController from
@ Property (nonatomic) UIImagePickerController * imgPickerController;
Changed:
@ Property (nonatomic, weak) UIImagePickerController * imgPickerController;
Then the warning is cleared.
Note: Sometimes Xcode cannot eliminate warnings and errors in time. You need to manually go to Product> Clean.
[Summary]
It is like a Property variable. If the reference type is not specified, the default value is strong reference. Here, we change it to weak to release this warning.
In addition, for more detailed meanings such as weak and strong, sort them out when necessary.
// Camera
-(Void) takePhotoAction :( UIButton *) sender {
FZLog (nil, nil );
// Set sourceType to the camera, and then determine whether the camera is available (ipod) without a camera. If sourceType is not set to a photo library
If ([UIImagePickerControllerisSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]) {
UIImagePickerController * picker = [[UIImagePickerControlleralloc] init]; // Initialization
Picker. delegate = self;
Picker. allowsEditing = YES; // You can edit the settings.
/* SourceType = UIImagePickerControllerSourceTypeCamera; // camera
SourceType = UIImagePickerControllerSourceTypePhotoLibrary; // Image Library
SourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; // Save the photo
*/
Picker. sourceType = UIImagePickerControllerSourceTypeCamera;
[SelfpresentViewController: picker animated: YEScompletion: nil]; // enter the camera page
}
}
// Open the album: (pad and iphone are differentiated)
-(Void) openPhotosAction :( UIButton *) sender {
// For iphone:
UIImagePickerController * pickerImage = [[UIImagePickerControlleralloc] init];
If ([UIImagePickerControllerisSourceTypeAvailable: UIImagePickerControllerSourceTypePhotoLibrary]) {
PickerImage. sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// PickerImage. sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
PickerImage. mediaTypes = [UIImagePickerControlleravailableMediaTypesForSourceType: pickerImage. sourceType];
}
PickerImage. delegate = self;
PickerImage. allowsEditing = NO;
[SelfpresentViewController: pickerImage animated: YEScompletion: nil]; // enter the camera page
}
// For ipad:
-(Void) ipadPicker {
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
// SourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum; // Save the photo
UIImagePickerController * picker = [[UIImagePickerControlleralloc] init];
Picker. delegate = self;
Picker. allowsEditing = NO; // whether to allow editing
Picker. sourceType = sourceType;
/*
If it is displayed from a navigation button, use:
PresentPopoverFromBarButtonItem: permittedArrowDirections ctions: animated :;
To render a view, use:
PresentPopoverFromRect: inView: permittedArrowDirections ctions: animated:
If the device is rotated, You need to locate the location in the following method of the parent View Controller:
DidRotateFromInterfaceOrientation :( reset rect in this method body)
Then call again:
-(Void) presentpoverfromrect :( CGRect) rect inView :( UIView *) view permittedArrowDirections :( UIPopoverArrowDirection) arrowDirections animated :( BOOL) animated
*/
// UIPopoverController can only be used on ipad devices. It is used to display temporary content. It is always displayed at the front of the current view and disappears automatically when you click somewhere else on the interface.
UIPopoverController * popover = [[UIPopoverControlleralloc] initWithContentViewController: picker];
// PermittedArrowDirections ctions sets the arrow direction.
[Popover presentpoverfromrect: CGRectMake (300,300,) inView: self. viewpermittedArrowDirections ctions: UIPopoverArrowDirectionAnyanimated: YES];
}
Call the camera to customize "Chinese display, camera full screen"
Chinese camera
The Iphone uses UIImagePickerController to call a system camera. This article describes how to call a system camera. However, sometimes I need to customize the camera content and add other controls to the view based on the camera content. Below is an example of the camera trying to maximize.
-(Void) onClickbutton :( id) sender
{
UIImagePickerController * controller = [[UIImagePickerControlleralloc] init];
[Controller setSourceType: UIImagePickerControllerSourceTypeCamera];
[ControllersetShowsCameraControls: NO];
CGAffineTransform cameraTransform = CGAffineTransformMakeScale (1.25, 1.25 );
Controller. cameraViewTransform = cameraTransform;
[SelfpresentViewController: controller animated: YEScompletion: nil]; // enter the camera page
}
Targets-> custom iOS target properties (Localization native development region is set to China)