gpt4 book ai didi

带有相机弹出窗口的 iOS 应用

转载 作者:行者123 更新时间:2023-11-29 12:45:34 25 4
gpt4 key购买 nike

我正在 xcode 5 中开发 iOS 7 应用程序。我正在使用相机功能。当用户在我的应用程序中按下相机按钮时,我想给他一个选择:拍摄新照片或从“照片流”中选择一张照片。我想显示一个带有选项的弹出窗口,就像“WhatsApp”那样,或者像 Apple Message 应用程序那样。

我想;我创建了一个包含一个部分和三个单元格的 TableView Controller :拍照,从“照片流”中选择并取消。我将此部分设置在表格 View 的底部,并使背景透明。但这是行不通的 ;)

我也在 Google 上搜索过,但没有找到任何可以帮助我的东西。

谁能告诉我怎么做?

最佳答案

试试这个。你必须使用 UIActionSheetDelegateUIImagePickerControllerDelegate

- (IBAction)changePhotoButtonPressed:(id)sender {
UIActionSheet *actionSheet=[[UIActionSheet alloc] initWithTitle:@"MY APP"
delegate:self
cancelButtonTitle: nil
destructiveButtonTitle: nil
otherButtonTitles:@"Take From Camera",@"Select From Library", @"Cancel", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
actionSheet.destructiveButtonIndex=2;
[actionSheet showInView:[UIApplication sharedApplication].keyWindow];
}

UIActionSheet 委托(delegate)

-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {

if (buttonIndex==0) {
[self takePictureFromCamera];
}
else if (buttonIndex==1) {
[self pickImageFromLibrary];

}
}

其他方法:

-(void) pickImageFromLibrary
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {

UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init];
self.imagePicker = imgPicker;
//UI Customization
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]];
}

self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.imagePicker.delegate = self;

[self presentViewController:self.imagePicker animated:YES completion:nil];

} else {
NSLog(@"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary);
}

}

-(void) takePictureFromCamera
{

if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

UIImagePickerController* imgPicker=[[UIImagePickerController alloc] init];
self.imagePicker = imgPicker;
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.delegate = self;
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0) {
[[self.imagePicker navigationBar] setTintColor:[UIColor whiteColor]];
}

[self presentViewController:self.imagePicker animated:YES completion:nil];

} else {
NSLog(@"Attempted to pick an image with illegal source type '%d'", UIImagePickerControllerSourceTypePhotoLibrary);

UIAlertView* alert = [[UIAlertView alloc] initWithTitle:@"MY APP" message:@"CAMERA_NOT_AVAILABLE" delegate:self cancelButtonTitle:@"OK" otherButtonTitles: nil];
[alert show];
}
}

关于带有相机弹出窗口的 iOS 应用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/23760466/

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