2017-02-13 3 views
1

Я использую UIImagePickerController для открытия камеры в своем приложении, и она не показывает кнопку сохранения и отмены вместе с кнопкой захвата.Камера не показывает кнопку сохранения/отмены после захвата?

Для реализации этого я использую объектив-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]; 
    } 
} 
+0

Это довольно много кода, чтобы свалить на вопрос здесь. Можете ли вы урезать пример в случае меньшего размера, который по-прежнему имеет ту же проблему? – halfer

ответ

0

Кнопка сохранения/отмены является частью разрешенийEditing, она появляется только после захвата. Кроме того, вы не должны использовать self.view addSubview, , а скорее:

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

+0

дает эту ошибку: --- Нет видимого @interface для 'CameraViewController' объявляет селектор 'presentViewController: анимированный:' –

+0

Iv'e отредактировал мой ответ, забыли часть «завершение: ноль» – unkgd

+0

Тем не менее он находится в том же состоянии ... не отображать кнопку сохранения/отмены после захвата. –

Смежные вопросы