拍摄后相机没有显示 save/cancel 按钮?

Camera is not showing save/cancel button after capturing?

我正在使用 UIImagePickerController 在我的应用程序中打开相机,它也没有显示保存和取消按钮以及捕捉按钮。

为了实现这一点,我使用了 objective-c。

- (void)viewDidLoad {
    [super viewDidLoad];

    pickernew = [[UIImagePickerController alloc] init];
    pickernew.sourceType = UIImagePickerControllerSourceTypeCamera;
    pickernew.delegate = self;
    pickernew.allowsEditing = YES;
    [self.view addSubview:pickernew.view];
    deviceOrientationCameraLoad=[UIApplication sharedApplication].statusBarOrientation;
    //nidhi
    [pickernew setShowsCameraControls:YES];

}

-(void)cameraRotetion
{

    if(IS_OS_8_OR_LATER) {
    switch (deviceOrientationCameraLoad) {
        case UIInterfaceOrientationLandscapeLeft:
            [self dipslandscapLeft];

            break;

        case UIInterfaceOrientationLandscapeRight:

            [self dipslandscapRight];

            break;

        case UIInterfaceOrientationPortraitUpsideDown:

            [self dipsPortaitdown];

            break;

        case UIInterfaceOrientationPortrait:
             [self dipsPortait];
            break;
         case UIInterfaceOrientationUnknown:
         [self dipsPortait];
            break;
        default:
            break;

     }

  }
-(void)dipsPortait
{
    CGFloat scaleFactor=1.3f;
   UIInterfaceOrientation deviceOrientationCamera = [UIApplication sharedApplication].statusBarOrientation;
    NSLog(@"before %ld",(long)deviceOrientationCamera);
    //    switch ([UIApplication sharedApplication].statusBarOrientation) {
    switch (deviceOrientationCamera) {
        case UIInterfaceOrientationLandscapeLeft:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationLandscapeRight:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortraitUpsideDown:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -180 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortrait:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);
            break;

        case UIInterfaceOrientationUnknown:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);
            break;

        default:
            break;
    }


}
-(void)dipsPortaitdown
{
    CGFloat scaleFactor=1.3f;
   UIInterfaceOrientation deviceOrientationCamera = [UIApplication sharedApplication].statusBarOrientation;
    NSLog(@"before %ld",(long)deviceOrientationCamera);
    //    switch ([UIApplication sharedApplication].statusBarOrientation) {
    switch (deviceOrientationCamera) {
        case UIInterfaceOrientationLandscapeLeft:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationLandscapeRight:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortraitUpsideDown:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortrait:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -180 / 180.0), scaleFactor, scaleFactor);
            break;

        case UIInterfaceOrientationUnknown:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);
            break;

        default:
            break;
    }

}
-(void)dipslandscapLeft
{
    CGFloat scaleFactor=1.3f;
    UIInterfaceOrientation deviceOrientationCamera = [UIApplication sharedApplication].statusBarOrientation;
    NSLog(@"before %ld",(long)deviceOrientationCamera);
    //    switch ([UIApplication sharedApplication].statusBarOrientation) {
    switch (deviceOrientationCamera) {
        case UIInterfaceOrientationLandscapeLeft:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationLandscapeRight:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -180 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortraitUpsideDown:

             pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortrait:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationUnknown:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);

            break;

        default:
            break;
    }

}

-(void)dipslandscapRight
{
    CGFloat scaleFactor=1.3f;
     UIInterfaceOrientation deviceOrientationCamera = [UIApplication sharedApplication].statusBarOrientation;
    NSLog(@"before %ld",(long)deviceOrientationCamera);
    //    switch ([UIApplication sharedApplication].statusBarOrientation) {
    switch (deviceOrientationCamera) {
        case UIInterfaceOrientationLandscapeLeft:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -180 / 180.0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationLandscapeRight:
             pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);

            break;

        case UIInterfaceOrientationPortraitUpsideDown:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);
            break;

        case UIInterfaceOrientationPortrait:

            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);
            break;

        case UIInterfaceOrientationUnknown:
            pickernew.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(0), scaleFactor, scaleFactor);
            break;

        default:
            break;
    }

}

-(void)objectCurrent1:(UIPopoverController*)pop currentTag:(int)tagCurr lineId:(NSString *)lineId headerId:(NSString *)headerId userDbId:(int)userDBId{
    popup = pop;
    tagC = tagCurr;
    header_Id = headerId;
    line_Id = lineId;
    User_Db_Id = userDBId;
}
- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}
- (void)viewWillAppear:(BOOL)animated
{
        if (IS_OS_8_OR_LATER)
        {
            if([[UIDevice currentDevice]orientation] == UIDeviceOrientationFaceUp)
            {
                if([UIApplication sharedApplication].statusBarOrientation == UIInterfaceOrientationLandscapeLeft)
                {
                    [[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeRight] forKey:@"orientation"];
                }
                else
                {
                    [[UIDevice currentDevice]setValue:[NSNumber numberWithInteger:UIDeviceOrientationLandscapeLeft] forKey:@"orientation"];
                }
            }
        }

        deviceOrientation = [[UIApplication sharedApplication] statusBarOrientation];

        if(deviceOrientation == UIInterfaceOrientationPortrait || deviceOrientation == UIInterfaceOrientationPortraitUpsideDown) {
            [self portraitView];
        }

        if(deviceOrientation == UIInterfaceOrientationLandscapeRight || deviceOrientation == UIInterfaceOrientationLandscapeLeft) {
            [self landscapeView];
        }
    //[self cameraRotetion];
    [super viewWillAppear:animated];
}

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo
{

}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {

    UIImage *imgTaken;
    NSString *docsDir,*imgNewPath;
    NSData *imgData;
    docsDir = [NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,NSUserDomainMask, YES) objectAtIndex:0];

    imgTaken = info[UIImagePickerControllerOriginalImage];
    imgNewPath = [NSTemporaryDirectory() stringByAppendingPathComponent:[NSString stringWithFormat:@"image%@%@%d.png",line_Id,header_Id,User_Db_Id]];
    UIImage *image1 = [self resizeImage:imgTaken];
    //imgData = UIImageJPEGRepresentation(imgTaken, 0.25);
    imgData = UIImagePNGRepresentation(image1);
    [imgData writeToFile:imgNewPath atomically:YES];
    [popup dismissPopoverAnimated:YES];
    pickernew = nil;
}

-(UIImage *)resizeImage :(UIImage *)theImage {
    CGSize theNewSize = {400, 400}; ///{width, height}
    UIGraphicsBeginImageContextWithOptions(theNewSize, NO, 1.0);
    [theImage drawInRect:CGRectMake(0, 0, theNewSize.width, theNewSize.height)];
    UIImage *newImage = UIGraphicsGetImageFromCurrentImageContext();
    UIGraphicsEndImageContext();
    return newImage;
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker {

//    [picker dismissViewControllerAnimated:YES completion:nil];
//    [pickernew dismissViewControllerAnimated:YES completion:nil];
//    [picker removeFromParentViewController];
//    [pickernew removeFromParentViewController];
    [popup dismissPopoverAnimated:YES];
    //[pickernew removeFromSubView];
    pickernew = nil;

}
- (void)cancelButtonPressed:(id)sender {
   // [self.captureSession stopRunning]; //stop the capture session
    [self.presentingViewController dismissViewControllerAnimated:YES completion:nil]; // dismiss the current view controller
}



- (void)viewDidAppear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter]addObserver:self selector:@selector(onOrientationChange:) name:UIDeviceOrientationDidChangeNotification object:nil];

    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
    [super viewDidAppear:animated];
}

- (void)viewWillDisappear:(BOOL)animated
{
    [[NSNotificationCenter defaultCenter] removeObserver:self name:UIDeviceOrientationDidChangeNotification object:nil];
    [super viewWillDisappear:animated];
}


-(void)portraitView{
    if (pickernew) {
         [self cameraRotetion];
    }


}

-(void)landscapeView{
    if (pickernew) {
        [self cameraRotetion];
    }
}

保存/取消按钮是允许编辑的一部分,它只出现post-capture。另外,你不应该使用 self.view addSubview, 而是:

[self presentViewController:pickerView animated:YES completion:nil]