zoukankan      html  css  js  c++  java
  • ios 选择图片

    1.控制器实现代理:
      UIActionSheetDelegate,UIImagePickerControllerDelegate,UINavigationControllerDelegate

    2.对图片添加手势:
      UITapGestureRecognizer *gs=[[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(choicePic)];
        [picImageView addGestureRecognizer:gs];
        picImageView.userInteractionEnabled=YES;

    3.实现手势对应方法:
       UIActionSheet *sheet=[[UIActionSheet alloc]initWithTitle:SHEET_PIC_SOURCE_TITLE delegate:self cancelButtonTitle:SHEET_PIC_SOURCE_CACEL destructiveButtonTitle:nil otherButtonTitles:SHEET_PIC_SOURCE_CAMERA,SHEET_PIC_SOURCE_PHOTO, nil];
        [sheet showInView:self.view];

    4.实现sheet对应代理方法:
      -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
        UIImagePickerController *picker = [[UIImagePickerController alloc] init];
        picker.delegate=self;
        if(buttonIndex==0){
            if([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
                 picker.sourceType = UIImagePickerControllerSourceTypeCamera;
            }else{
                [UtilTool ShowAlertView:ALERT_WARN_TITLE setMsg:OPEN_CAMERA_ERRORMSG];
            }
            [self presentViewController:picker animated:YES completion:nil];
        }else if (buttonIndex==1){
            picker.sourceType=UIImagePickerControllerSourceTypePhotoLibrary;
            [self presentViewController:picker animated:YES completion:nil];
        }else{
        }
    }

    5.实现选择照片或照相机代理方法:
      -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info{
        [UIApplication sharedApplication].statusBarHidden=NO;
        [picker dismissViewControllerAnimated:YES completion:nil];
        
        NSString *mediaType=[info objectForKey:UIImagePickerControllerMediaType];
        if([mediaType isEqualToString:@"public.image"]){
            UIImage *image=[info objectForKey:UIImagePickerControllerOriginalImage];
            
            picImageView.image=image;
            

       //目的:判断是否选择了图片,可以简单判断是否需要上传图片
            //isPic=1;
            
            if(picker.sourceType == UIImagePickerControllerSourceTypeCamera)
                UIImageWriteToSavedPhotosAlbum(image, nil, nil, nil);
        }
    }

  • 相关阅读:
    AIO系列文档(2)----TIO使用
    AIO系列文档(1)----图解ByteBuffer
    Dubbo+zookeeper构建高可用分布式集群(二)-集群部署
    Dubbo+zookeeper构建高可用分布式集群(一)-单机部署
    利用redis + lua解决抢红包高并发的问题
    使用SIP Servlet为Java EE添加语音功能
    Java互联网架构-直播互动平台高并发分布式架构应用设计
    搭建自己的SIP服务器:开源sip服务器opensips的搭建及终端TwInkle的使用
    SIP协议搭建电信级VOIP/IM运营平台--架构篇(sip集群)
    阿里分布式事务解决方案-GTS
  • 原文地址:https://www.cnblogs.com/shareze/p/4064259.html
Copyright © 2011-2022 走看看