#import "CameraViewController.h"
@interface Cameraviewcontroller ()
@end
@implementation Cameraviewcontroller
– (void) Viewdidload {
[Super Viewdidload];
Nsarray *arr = @[@ "Call camera", @ "Call Picture library", @ "Turn off lights", @ "Turn off flash"];
for (int i = 0; i < 4; i++) {
UIButton *button = [UIButton buttonwithtype:uibuttontypecustom];
Button.frame = CGRectMake (+) * i + 50, 100, 100);
[Button Settitle:arr[i] forstate: (UIControlStateNormal)];
[Button Settitlecolor:[uicolor Blackcolor] forstate: (UIControlStateNormal)];
if (i = = 0) {
[Button addtarget:self action: @selector (Addcarema) forControlEvents: (UIControlEventTouchUpInside)];
}else if (i = = 1)
{
[Button addtarget:self action: @selector (Openpiclibrary) forControlEvents: (UIControlEventTouchUpInside)];
}else if (i = = 2)
{
[Button addtarget:self action: @selector (Openflashlight) forControlEvents: (UIControlEventTouchUpInside)];
}
else if (i = = 3)
{
[Button addtarget:self action: @selector (Closeflashlight) forControlEvents: (UIControlEventTouchUpInside)];
}
[Self.view Addsubview:button];
}
Do no additional setup after loading the view.
}
-(void) Addcarema
{
The emulator cannot use this feature to determine if the camera can be turned on
if ([Uiimagepickercontroller issourcetypeavailable: (Uiimagepickercontrollersourcetypecamera)]) {
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
Picker.delegate = self;
picker.allowsediting = YES; Whether to edit
Camera
Picker.sourcetype = Uiimagepickercontrollersourcetypecamera;
[Self Presentviewcontroller:picker animated:yes completion:nil];
}else
{
If the user is not prompted
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Error" message:@ "You don't have a webcam delegate:nil cancelbuttontitle:@" drat! "Otherbuttontitles:nil, nil];
[Alert show];
}
}
How to execute after the shot is complete
-(void) Imagepickercontroller: (Uiimagepickercontroller *) Picker Didfinishpickingmediawithinfo: (nsdictionary *) info
{
Get Pictures
UIImage *image = [info objectforkey:uiimagepickercontrolleroriginalimage];
Picture in album
Uiimagewritetosavedphotosalbum (image, nil, nil, nil);
[Self dismissviewcontrolleranimated:yes completion:nil];
}
Execute method after clicking Cancel button
-(void) Imagepickercontrollerdidcancel: (Uiimagepickercontroller *) picker
{
[Self dismissviewcontrolleranimated:yes completion:nil];
}
-(void) openpiclibrary
{
Albums can be opened with an emulator
if ([Uiimagepickercontroller issourcetypeavailable:uiimagepickercontrollersourcetypephotolibrary]) {
Uiimagepickercontroller *picker = [[Uiimagepickercontroller alloc] init];
Picker.delegate = self;
picker.allowsediting = YES;
Open album Select photos
Picker.sourcetype = uiimagepickercontrollersourcetypephotolibrary;
[Self Presentviewcontroller:picker animated:yes completion:nil];
}else
{
Uialertview *alert = [[Uialertview alloc] initwithtitle:@ "Error" message:@ "You don't have a webcam delegate:nil cancelbuttontitle:@" drat! "Otherbuttontitles:nil, nil];
[Alert show];
}
}
-(void) openflashlight
{
Avcapturedevice *device = [Avcapturedevice defaultdevicewithmediatype:avmediatypevideo];
if ([device Hastorch]) {
[Device Lockforconfiguration:nil];
[Device Settorchmode:avcapturetorchmodeoff];
[Device unlockforconfiguration];
}
}
-(void) closeflashlight
{
[Self. Avsession stoprunning];
}
– (void) Didreceivememorywarning {
[Super didreceivememorywarning];
Dispose of any of the can is recreated.
}
/*
#pragma mark–navigation
In a storyboard-based application, your'll often want to do a little preparation before navigation
– (void) Prepareforsegue: (Uistoryboardsegue *) Segue Sender: (ID) Sender {
Get the new view controller using [Segue Destinationviewcontroller].
Pass the selected object to the new view controller.
}
*/
@end