簡體   English   中英

拍攝后相機未顯示保存/取消按鈕?

[英]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];
    }
}

保存/取消按鈕是allowsEditing的一部分,它僅在捕獲后出現。 此外,您不應該使用self.view addSubview,而是:

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM