0

我有一个按钮,当用户按下它时,他会被导航到相机拍照。

当他拍照时,他按下完成并返回控制器。但是当这种情况发生时,导航栏会出现在屏幕上,低于电话的电池/信号栏。奇怪的是,这发生在 4/4s 而不是 3gs

4

1 回答 1

1

在不了解更多细节的情况下回答这个问题相当困难,但这里有一些代码我用来调出相机,拍照,然后成功关闭相机。该方法可以通过使用一行代码来调用:[self takePhoto];

- (void) takePhoto {

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
        //Clear out the UI first

        UIImagePickerController *picker = [[UIImagePickerController alloc] init];

        picker.delegate = self;

        picker.sourceType = UIImagePickerControllerSourceTypeCamera;
        //picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary; -> use this if you want them to select from the library
        [self presentViewController:picker animated:YES completion:nil];
    } else {
        //Device does not support a camera, show a message if desired
    }

}

然后你需要一个委托,这样程序就知道在拍摄或选择图像时要做什么以及如何关闭,这就是这段代码:

- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
    self.workingImage = nil;

    //I grab the image and store globally, but first I manually scale and rotate it if necessary    
    self.workingImage = [self scaleAndRotateImage:[info objectForKey:UIImagePickerControllerOriginalImage]];

    //I display the image in my UI view, so this chunk of code will size it properly
    CGRect bound;
    bound.origin = CGPointZero;
    bound.size = img.size;
    imageView.bounds = bound;

    //Set the UI image view and dismiss the controller
    [imageView setImage:self.workingImage];
    [picker dismissModalViewControllerAnimated:YES];

}

显然,请确保您的控制器 .h 正确实现委托,如下所示:

@interface ViewController : UIViewController<UIImagePickerControllerDelegate> { ... }

希望这可以帮助?

于 2012-07-20T12:38:54.357 回答