• 打开相册另类写法


    - (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;
    }
  • 相关阅读:
    排序
    洛谷P1071 字符串
    编写ui自动化问题总结
    fastdfs跨服务器数据迁移
    JMeter随机上传附件
    抓包工具介绍
    idea2019.1版本永久版破解
    使用nodejs模拟http接口的返回
    配置RHEL&CentOS网络说明
    linux测试最最最最基本操作命令
  • 原文地址:https://www.cnblogs.com/songxing10000/p/4823037.html
Copyright © 2020-2023  润新知