UIAction的使用和调用系统相册和相机

实现UIActionSheetDelegate


UIActionSheet *menu = [[UIActionSheet alloc]

                           initWithTitle@""

                           delegate:self

                           cancelButtonTitle:@"Cancel"

                           destructiveButtonTitle:nil

                           otherButtonTitles:@"图库相册",@"拍照"nil];

    [menu showInView:self.view];


# pragma mark UIActionSheet method

- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex

{

    if (buttonIndex==0) {

        [self photoalbumr];//图库相册

    

    }else if(buttonIndex==1){

         [self photocamera];//拍照

    }else if(buttonIndex==2){

    

    }


    

    [actionSheet release];

}



调用系统的相簿


实现UIImagePickerControllerDelegate


-(void)photoalbumr{

    if ([UIImagePickerController isSourceTypeAvailable:

         UIImagePickerControllerSourceTypePhotoLibrary]) {

        UIImagePickerController *picker =

        [[UIImagePickerController allocinit];

        picker.delegate = self;

        picker.allowsImageEditing = YES;

        picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;

        [self presentModalViewController:picker animated:YES];

        [picker release];

    }

    else {

        UIAlertView *alert = [[UIAlertView alloc

                              initWithTitle:@"Error accessing photo library" 

                              message:@"Device does not support a photo library" 

                              delegate:nil 

                              cancelButtonTitle:@"Drat!" 

                              otherButtonTitles:nil];

        [alert show];

        [alert release];

        

    }


}

-(void)photocamera{

    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {

        UIImagePickerController* imagepicker = [[UIImagePickerController allocinit];

        imagepicker.delegate = self;

        imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;

        imagepicker.modalTransitionStyle = UIModalTransitionStyleCoverVertical;

        imagepicker.allowsEditing = YES;

        [self presentModalViewController:imagepicker animated:YES];


    }

    else {

        UIAlertView *alert = [[UIAlertView alloc

                              initWithTitle:@"Sorry" 

                              message:@"设备不支持拍照功能" 

                              delegate:nil 

                              cancelButtonTitle:@"确定" 

                              otherButtonTitles:nil];

        [alert show];

        [alert release];

        

    }


  }

#pragma mark UIImagePicker method

- (void)imagePickerController:(UIImagePickerController *)picker 

        didFinishPickingImage:(UIImage *)image 

                  editingInfo:(NSDictionary *)editingInfo

{  

  /*将图片存储到document下

    NSArray *paths = NSSearchPathForDirectoriesInDomains(NSDocumentDirectory,     NSUserDomainMask,YES);

    NSString *documentsDirectory = [paths objectAtIndex:0];

    NSString *savedImagePath = [documentsDirectory stringByAppendingPathComponent:@"savedImage.png"];

    NSData *imageData = UIImagePNGRepresentation(image);

    [imageData writeToFile:savedImagePath atomically:NO];   

      _imgName=@"savedImage.png";

    self._imgFilePath=documentsDirectory;

    */

  

    [addPhoto setBackgroundImage:image forState:UIControlStateNormal];

   

     [picker dismissModalViewControllerAnimated:YES];


}


// 完成选取

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker

{

    [picker dismissModalViewControllerAnimated:YES];

}


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值