打开相册另类写法

- (IBAction)actionPhoto:(id)sender
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    PresentPhotoLibrary(self, YES);
}

#pragma mark - UIImagePickerControllerDelegate

//-------------------------------------------------------------------------------------------------------------------------------------------------
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
//-------------------------------------------------------------------------------------------------------------------------------------------------
{………………}
//-------------------------------------------------------------------------------------------------------------------------------------------------
BOOL PresentPhotoLibrary(id target, BOOL canEdit)
//-------------------------------------------------------------------------------------------------------------------------------------------------
{
    if (([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary] == NO
         && [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum] == NO)) return NO;
    //---------------------------------------------------------------------------------------------------------------------------------------------
    NSString *type = (NSString *)kUTTypeImage;
    UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
    //---------------------------------------------------------------------------------------------------------------------------------------------
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]
        && [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypePhotoLibrary] containsObject:type])
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        imagePicker.mediaTypes = [NSArray arrayWithObject:type];
    }
    else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]
             && [[UIImagePickerController availableMediaTypesForSourceType:UIImagePickerControllerSourceTypeSavedPhotosAlbum] containsObject:type])
    {
        imagePicker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
        imagePicker.mediaTypes = [NSArray arrayWithObject:type];
    }
    else return NO;
    //---------------------------------------------------------------------------------------------------------------------------------------------
    imagePicker.allowsEditing = canEdit;
    imagePicker.delegate = target;
    [target presentViewController:imagePicker animated:YES completion:nil];
    //---------------------------------------------------------------------------------------------------------------------------------------------
    return YES;
}
时间: 2024-10-19 06:59:41

打开相册另类写法的相关文章

Android 打开相册,选择一张图片并返回

一  打开相册 private static final int ALBUM_OK = 0; Intent albumIntent = new Intent(Intent.ACTION_PICK, null); albumIntent.setDataAndType( MediaStore.Images.Media.EXTERNAL_CONTENT_URI, "image/*"); startActivityForResult(albumIntent, ALBUM_OK); 二  显示图

IOS 打开照相机 打开相册

/** * 打开照相机 */ - (void)openCamera { if (![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) return; UIImagePickerController *ipc = [[UIImagePickerController alloc] init]; ipc.sourceType = UIImagePickerControllerS

分享WEBAPP利用纯HTML5实现拨打电话,打开相册,打开摄像头源码

一:实现打电话或发短信 <a href="tel:10086">拨打10086</a> <a href="sms:10086">发短信</a> 二:实现打开相册 <input type="file" accept="image/*"/> 三:实现打开相机 <input type="file" capture="camera"

HTML5 开发APP(打开相册以及图片上传)

我们开发app,常常会遇到让用户上传文件的功能.比如让用户上传头像.我公司的业务要求是让用户上传支付宝收款二维码,来实现用户提现的功能.想要调用相册要靠HTML Plus来实现.先上效果图 基本功能是点击按钮就上传图片,然后获取到图片在服务器上的路径. 首先我们要打开相册,使用gallery模块管理系统相册来打开相册 mui('#shangchuan')[0].addEventListener('tap',function(){ chooseImg(); }) function chooseIm

iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.”

iOS频繁打开相册崩溃: ALAssetsLibrary error - “Too many contexts. No space in contextList.” http://stackoverflow.com/questions/13480611/has-anyone-experienced-crashes-when-using-alassetslibrary-in-a-background-thread 原因: 因为频繁的调用 [[ALAssetsLibrary alloc] init]

在iPad iOS8环境下打开相册或者拍照

在iPad下打开相册或者拍照,如果使用 UIImagePickerController 打开相册或者拍照,那必须要用到 UIPopoverController 去打开. UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker]; self.popoverController = popover; [self.popoverController presentP

android打开相册选取图片或打开相机拍照并进行裁剪

首先是打开本地相册选取图片: Intent albumIntent = new Intent(Intent.ACTION_PICK);//打开系统的相册 albumIntent.setType("image/*"); startActivityForResult(albumIntent, 0x1004); 选取完图片后在onActivityResult编写取数据的操作: @Override protected void onActivityResult(int requestCode,

手机端打开相册与上传图片

css: 1 .upload-img{ 2 width:80%; 3 position:fixed; 4 top:50%; 5 left:50%; 6 margin-left:-40%; 7 #fff; 8 border-radius: 10px; 9 z-index:1000; 10 display:none; 11 } 12 .upload-img>p:first-child{ 13 height:50px; 14 line-height: 50px; 15 border-bottom:2p

addEventListener 的另类写法

addEventListener 参数如下 addEventListener(type, listener[, useCapture]); type,事件名称 listener,事件处理器 useCapture,是否捕获 一直把 listener 记成是响应函数,function 类型.相信很多人也是这么理解的.多数时候是这么使用 elem.addEventListener('click', function(ev) { // todo }, false); 第一个参数没什么异议,第二个参数传一