gpt4 book ai didi

objective-c - iOS:尝试在应用程序中使用相机时 View Controller 崩溃。

转载 作者:行者123 更新时间:2023-11-29 04:32:13 25 4
gpt4 key购买 nike

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

当他拍照时,他按下“完成”并返回到 Controller 。但是,当发生这种情况时,导航栏会在屏幕上升起,低于电话所具有的电池/信号栏。奇怪的是,这种情况发生在 4/4s 上,但在 3gs 上却没有

最佳答案

在不了解更多细节的情况下很难回答这个问题,但这里有一些我用来调出相机,拍照,然后成功关闭相机的代码。一行代码即可调用该方法:[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
}

}

然后你需要一个委托(delegate)来完成这一切,以便程序知道在拍摄或选择图像时要做什么以及如何关闭,这就是这段代码的内容:

- (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];

}

显然,请确保您的 Controller .h 正确实现委托(delegate),如下所示:

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

希望这有帮助吗?

关于objective-c - iOS:尝试在应用程序中使用相机时 View Controller 崩溃。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11576692/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com