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);
        }
    }

  • 相关阅读:
    [HIHO1223]不等式(离散化,枚举)
    [NYIST15]括号匹配(二)(区间dp)
    [HIHO1328]逃离迷宫(bfs,位压)
    [Topcoder]AvoidRoads(dp,hash)
    [POJ1159]Palindrome(dp,滚动数组)
    [Topcoder]ZigZag(dp)
    [NYIST32]组合数(状压,枚举,暴力)
    [NYIST737]石子合并(一)(区间dp)
    [HIHO1322]树结构判定(并查集)
    [HIHO1143]骨牌覆盖问题·一(矩阵快速幂,递推)
  • 原文地址:https://www.cnblogs.com/shareze/p/4064259.html
Copyright © 2011-2022 走看看