0
点赞
收藏
分享

微信扫一扫

IOS照片选择

#pragma mark -
设置头像
- (void)handleSingleTap:(UIGestureRecognizer*)gestureRecognizer
 {
   
  UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"选择图片来源"
                                                           delegate:self
                                                  cancelButtonTitle:@"取消"
                                             destructiveButtonTitle:nil
                                                  otherButtonTitles:@"相机",@"相册", nil];
  
   [actionSheet showInView:self.view];
 }
 
 #pragma mark - UIActionSheetDelegate
void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
   
  picBool = NO;
  switch
      case 0:{
          //相机
           UIImagePickerController *controller = [self imagePickerControlerWithSourceType:UIImagePickerControllerSourceTypeCamera];
          if
               [self.tabBarController presentModalViewController:controller animated:YES];
          
      
          break;
      case 1:{
          //相册
           UIImagePickerController *controller = [self imagePickerControlerWithSourceType:UIImagePickerControllerSourceTypePhotoLibrary];
          if
               [self.tabBarController presentModalViewController:controller animated:YES];
          
           
      
          break;
      default:
          break;
  
   
 }
 
 
UIImagePickerController *)imagePickerControlerWithSourceType:(UIImagePickerControllerSourceType)imagePickerSourceType{
   
  if ([UIImagePickerController isSourceTypeAvailable:imagePickerSourceType]) {
       UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
       imagePicker.sourceType
       imagePicker.allowsEditing = NO;
       imagePicker.delegate = self;
      return
       
   }else{
       
      TKAlertCenter defaultCenter] postAlertWithMessage:@"您的手机不支持拍照操作!"];
      return nil;
  
 }
 
elegate
 
void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary
   
   if([[info objectForKey:UIImagePickerControllerMediaType]
       isEqualToString:(NSString*)kUTTypeImage]) {
      //获取选中图片
       UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
       NSLog(@"imageSize.height:%f,imageSize.width:%f",image.size.height,image.size.width);
       
      if (image.size.width > image.size.height) {
          if (image.size.width>defaultPhotoSizeForEdit.width) {
              CGFloat ralta = defaultPhotoSizeForEdit.width/image.size.width;
              CGSize newSize = CGSizeMake(defaultPhotoSizeForEdit.width, image.size.height*ralta);
               image = [image resizedImage:newSize interpolationQuality:kCGInterpolationMedium];
          
           
       }else{
          if (image.size.height>defaultPhotoSizeForEdit.height) {
              CGFloat ralta = defaultPhotoSizeForEdit.height/image.size.height;
              CGSize newSize = CGSizeMake(image.size.width*ralta,defaultPhotoSizeForEdit.height);
               image = [image resizedImage:newSize interpolationQuality:kCGInterpolationMedium];
          
      
       
       NSLog(@"new--imageSize.height:%f,new --imageSize.width:%f",image.size.height,image.size.width);
       
       dismissViewControllerAnimated:YES completion:^{
          //跳转到图片编辑界面
           PhotoEditViewController *photoEditView PhotoEditViewController alloc]initWithNibName:@"PhotoEditViewController" bundle:nil];
           
           photoEditView.imageForEdit
           photoEditView.delegate = self;
           photoEditView.hidesBottomBarWhenPushed
          
           [self.navigationController pushViewController:photoEditView animated:YES];
      
       
       
      return;
  
 
   
   //获取选中图片
   UIImage *image = [info objectForKey:UIImagePickerControllerEditedImage];
   NSLog(@"imageSize.height:%f,imageSize.width:%f",image.size.height,image.size.width);    
  
  
   [self showProgressHUDWithMessage:@"图片正在上传"];
   [[DataModel sharedDataModel] requestUploadMyIconWithImage:image];    
   
   dismissModalViewControllerAnimated:YES];
 }
 
void)imagePickerControllerDidCancel:(UIImagePickerController
   dismissModalViewControllerAnimated:YES];
   
 }IOS

举报

相关推荐

0 条评论