ios - 弹出 View 选择图像

标签 ios uiview uiimagepickercontroller

我想创建一个如下图所示的示例,而是从照片库中选择图像或使用相机拍照(如 facebook 应用程序)。此 View 是内置 View 还是我需要创建自定义 View ?

Example

最佳答案

所以你想要一个 UIActionSheet?

这样做:

UIActionSheet *actionSheet = [[UIActionSheet alloc] 
                                  initWithTitle:@"What do you want to do?" 
                                  delegate:self 
                                  cancelButtonTitle:@"Cancel" 
                                  destructiveButtonTitle:nil 
                                  otherButtonTitles:@"Camera", @"Photos", nil];
    [actionSheet showInView:self.view];
    [actionSheet release];

然后在 clickedButtonAtIndex 中执行如下操作:

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
    UIImagePickerController *picker = [[UIImagePickerController alloc] init];
    picker.delegate = self;

    if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Camera"]) {
        picker.sourceType = UIImagePickerControllerSourceTypeCamera; 
    } 
    else if ([[actionSheet buttonTitleAtIndex:buttonIndex] isEqualToString:@"Photos"]) {
        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
    }
   [self presentModalViewController:picker animated:YES];
   [picker release];
}

关于ios - 弹出 View 选择图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11002682/

相关文章:

ios - 捕获并记录 UIView 上的触摸事件

iOS:在 Storyboard中将子类从 UIView 更改为 UIScrollView

ios - Objective C - 来自相机的图像设置在 UIButton 上

ios - UIImagePickerController 在 iOS 设备上工作但不在 iOS 模拟器上工作?

ios - 用 NSObject 替换 NSMutableArray 并在 UITableView 中读取它

iOS FirebaseCloudMessaging 通知在调试/测试飞行或发布中不起作用

ios - 如何在不隐藏最后添加的 subview 的情况下添加多个 subview ?

javascript - 设置合适的视口(viewport),与 ios 和 android 兼容,可与旋转配合使用

android - 翻转拨动开关看起来是矩形而不是圆形

ios - "Access your photos"权限对话框显示在错误的 View 中