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

标签 ios iphone objective-c popup whatsapp

我正在 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/

相关文章:

iphone - 更改数组中对象的顺序而不调用它

ios - swift 3 : Error in copying file with FileManager

ios - 如何从可选函数 didMoveToPage 中获取索引?

iphone - 将后退按钮设置为自定义 UIImage

iphone - 3D立方体问题!第1部分

objective-c - 在哪里存储项目范围的配置变量?

ios - 为什么 Xcode 中的起始项目 "OpenGL Game"有 2 个立方体?

objective-c - IOS:字符串强调和粗体

ios - 如何检测应用程序是否在越狱设备上运行?

html 视频不在 iphone 上加载但在桌面网络和 android 上加载