• 添加相册或拍照更改头像


    添加代理<UIImagePickerControllerDelegate,UINavigationControllerDelegate>
    
    首先在点击事件中添加滑出菜单
    
    - (IBAction)editAvatarAction:(UIButton *)sender
    
    {
        UIActionSheet *sheet = [[UIActionSheet alloc] initWithTitle:@"上传头像" delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"拍照", @"相册", nil];
    
        [sheet showInView:self.view];
    }
    
    然后在actionSheet的代理方法中选择拍照或相册
    
    -(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
    
    {
        switch (buttonIndex)
        {
            case 0://拍照
            {
                BOOL isCameraSupport = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera];
                if(isCameraSupport){
                    UIImagePickerController *imagepicker = [[UIImagePickerController alloc]init];
                    imagepicker.sourceType = UIImagePickerControllerSourceTypeCamera;
                    imagepicker.allowsEditing = YES;
                    imagepicker.delegate = self;
                    [self presentViewController:imagepicker animated:YES completion:nil];
                }
            }
                break;
            case 1://相册
            {
                BOOL isCameraSupport = [UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary];
                if(isCameraSupport){
                    UIImagePickerController *imagepicker = [[UIImagePickerController alloc]init];
                    imagepicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
                    imagepicker.allowsEditing = YES;
                    imagepicker.delegate = self;
                    [self presentViewController:imagepicker animated:YES completion:nil];
                }
            }
                break;            
            default:
                break;
        }
    }
    
    //最后在UIImagePickerControllerDelegate代理方法(确认选取)
    -(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
    {
        [picker dismissViewControllerAnimated:YES completion:^{
            UIImage *image = info[UIImagePickerControllerEditedImage];//获取选取的图片
    }
    
  • 相关阅读:
    网页截图软件
    JavaScript的写类方式(3)
    XMLHttpRequest与script对比
    JavaScript的写类方式(5)
    Java方法传值和传引用
    变量的显示/隐式声明
    用递归实现十进制数转换N进制
    Javascript中克隆一个数组
    JavaScript1.6数组新特性和JQuery的几个工具方法
    HTML P不能包含块级元素(包括自身)
  • 原文地址:https://www.cnblogs.com/wlsxmhz/p/5338204.html
Copyright © 2020-2023  润新知