简体   繁体   English

拍摄后相机未显示保存/取消按钮?

[英]Camera is not showing save/cancel button after capturing?

I am using UIImagePickerController to open camera in my App, and it is not showing save and cancel button along with capture button also. 我正在使用UIImagePickerController在我的应用程序中打开相机,它也没有显示保存和取消按钮以及捕获按钮。

To implement this I am using objective-c. 为了实现这一点,我使用的是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];
    }
}

The save / cancel button are part of the allowsEditing, it only appears post-capture. 保存/取消按钮是allowsEditing的一部分,它仅在捕获后出现。 Also, you should not use self.view addSubview, but rather: 此外,您不应该使用self.view addSubview,而是:

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

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 从UIImagePickerController捕获图像后,相机显示黑色图像 - Camera showing black image after capturing image from UIImagePickerController 在 UIImagePickerController 中,取消按钮未显示? - In UIImagePickerController Cancel button not showing? 在UIActionSheet中,取消按钮不显示给iphone吗? - In UIActionSheet the cancel button not showing for iphone? 从自定义相机中删除取消按钮 - Removing the cancel button from Custom camera 允许使用UIImagePickerController捕获照片,直到单击“取消”按钮为止 - Allow capturing photos using UIImagePickerController until cancel button clicked 取消按钮未显示在iPad模式下的UINavigationController中 - Cancel button not showing up in UINavigationController in modal for iPad iOS 10相机视图显示API_Cancel_Title而不是取消 - iOS 10 Camera view showing API_Cancel_Title instead of Cancel 使用UIImagePickerController自定义“使用”,“取消”,“重拍”和“倒车”按钮事件 - Custom “Use”, “Cancel”,“Retake” and “Reverse Camera” button event using UIImagePickerController image_picker:如果首先访问相机,则取消按钮在图库中不可见 - image_picker: Cancel button not visible in gallery, if camera was accessed first 旋转取消按钮后,TableViewController UISearchBar不可单击 - TableViewController UISearchBar after rotation cancel button not clickable
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM