美文网首页
iPad图片上传的方法

iPad图片上传的方法

作者: 左方 | 来源:发表于2019-11-21 11:59 被阅读0次

实现效果:


IMG_4677D226F011-1.jpeg

代码如下:
定义:

@property (nonatomic,strong) UIImagePickerController *imagePicker;
@property (nonatomic,strong) UIPopoverPresentationController* popover;

因为iPad打开照片选择器必须通过UIPopoverPresentationController。

在点击上传的按钮事件做以下操作:

- (IBAction) uploadBtnAct:(id)sender{
    self.imagePicker = [[UIImagePickerController alloc] init];
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
        self.imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
        self.imagePicker.mediaTypes = [NSArray arrayWithObject:(NSString *)kUTTypeMovie];
        self.imagePicker.navigationBar.translucent = NO;
        self.imagePicker.delegate = self;
        [self.imagePicker setAllowsEditing:NO];
        
        UIViewController *viewController = [[UIViewController alloc] init];
        UIView *pickerView = self.imagePicker.view;
        pickerView.translatesAutoresizingMaskIntoConstraints = NO;
        [viewController addChildViewController:self.imagePicker];
        [viewController.view addSubview:pickerView];
        viewController.modalPresentationStyle = UIModalPresentationPopover;
        
        UIButton *cameraButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
        [cameraButton setTitle:@"拍摄视频" forState:UIControlStateNormal];
        [cameraButton setTitleColor:UIColorFromRGB(0x007afc) forState:UIControlStateNormal];
        [cameraButton setFrame:CGRectMake(0, 200, CGRectGetWidth(viewController.view.frame), 44)];
        cameraButton.translatesAutoresizingMaskIntoConstraints = NO;
        [cameraButton addTarget:self action:@selector(handleCameraButtonEvent) forControlEvents:UIControlEventTouchUpInside];
        [viewController.view addSubview:cameraButton];
        
        [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"V:|-0-[pickerView]-0-[cameraButton(44)]-0-|" options:NSLayoutFormatDirectionLeadingToTrailing metrics:nil views:NSDictionaryOfVariableBindings(cameraButton,pickerView)]];
        [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[pickerView]-0-|" options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:nil views:NSDictionaryOfVariableBindings(pickerView)]];
        [viewController.view addConstraints:[NSLayoutConstraint constraintsWithVisualFormat:@"H:|-0-[cameraButton]-0-|" options:NSLayoutFormatAlignAllTop | NSLayoutFormatAlignAllBottom metrics:nil views:NSDictionaryOfVariableBindings(cameraButton)]];
        
        _popover = viewController.popoverPresentationController;
        _popover.sourceView = sender;
        _popover.sourceRect = CGRectMake(0, MYUPLOAD_HEADER_OFFSET, sender.bounds.size.width, button.bounds.size.height);
        _popover.permittedArrowDirections = UIPopoverArrowDirectionUp;
        [self.fatherVC presentViewController:viewController animated:YES completion:nil];
    }
}

- (void)handleCameraButtonEvent {
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == YES) {
        
        [self.imagePicker dismissViewControllerAnimated:YES completion:^{}];
        _popover = nil;
        self.imagePicker = [[UIImagePickerController alloc] init];
        self.imagePicker.navigationBar.translucent = NO;
        self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
        self.imagePicker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
        self.imagePicker.mediaTypes = @[(NSString*)kUTTypeMovie];
        self.imagePicker.videoQuality = UIImagePickerControllerQualityTypeHigh;
        self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModeVideo;
        self.imagePicker.videoMaximumDuration = 30*60;
        self.imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
        self.imagePicker.showsCameraControls = YES;
        self.imagePicker.delegate = self;
        @weakify(self)
        [self.fatherVC presentViewController:self.imagePicker animated:YES completion:^{
            @strongify(self)
            [self setCameraAuthorizationStatus];
        }];
    }
}

相关文章

  • iPad图片上传的方法

    实现效果: 代码如下:定义: 因为iPad打开照片选择器必须通过UIPopoverPresentationCont...

  • 提高上传效率,iOS图片压缩总结

    最近项目中用到七牛上传图片,多张上传时,png图片大,上传极慢,特地研究了一下图片压缩的方法。 两种压缩图片的方法...

  • Jquery图片转成base64

    可以实现图片预览上传,不用flash方法 php接收保存图片方法

  • App 预览和屏幕快照

    苹果上传APP审核需要上传APP屏幕快照,分别有3.5寸,4寸,4.7寸,5.5寸,5.8寸,ipad五种图片,对...

  • iTunes Connect上传APP屏幕快照图片尺寸

    苹果上传APP审核需要上传APP屏幕快照,分别有3.5寸,4寸,4.7寸,5.5寸,ipad五种图片,对应尺寸大小...

  • Markdown插入图片方法之 - Base64

    Markdown插入图片方法之 - Base64 在markdown中使用图片的常用方法: 使用本地图片[图片上传...

  • 使用AFN上传视频

    3年前有写过上传图片的文章,今天在这记录下上传视频的方法!上传图片和视频都属于文件上传(upload file),...

  • iOS-图片方向异常

    使用iPhone或者iPad拍照后上传图片,发现在电脑端显示的图片方向各异,而在手机上显示正常的问题如何避免 简单...

  • 一、ajax上传视频或者图片

    一。上传图片实例 基于thinkphp3.2做的上传,这里上传方法就不多说了。如果你想多的选择图片,需要在type...

  • springBoot 2.x 读取上传流文件

    网上有很多上传文件的教程,使用很不舒服,所以写了这读取上传流文件的方法,方法输出为String类型 图片上传功能方法

网友评论

      本文标题:iPad图片上传的方法

      本文链接:https://www.haomeiwen.com/subject/mdgzictx.html