- (void)initActionSheet
{
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:nil delegate:self cancelButtonTitle:@"取消" destructiveButtonTitle:nil otherButtonTitles:@"我的相册",@"拍照", nil];
actionSheet.tintColor = [UIColor whiteColor];
[actionSheet showInView:self.scrollerViewUpload];
}
#pragma mark - UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0)
{
UIImagePickerController *PickerController = [[UIImagePickerController alloc] init];
PickerController.delegate = self;
[self presentViewController:PickerController animated:YES completion:nil];
}
else if (buttonIndex == 1)
{
DNLog(@"拍照");
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
//判断是否有相机
if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
//设置拍照后的图片可被编辑
picker.allowsEditing = YES;
//资源类型为照相机
picker.sourceType = sourceType;
[self presentViewController:picker animated:YES completion:nil];
}else {
[SVProgressHUD showWithStatus:@"没有照相功能" maskType:SVProgressHUDMaskTypeBlack];
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(2.0 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[SVProgressHUD dismiss];
});
DNLog(@"没有照相功能");
}
}
}
#pragma mark - UIImagePickerControllerDelegate
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
UIImage *imageNew =info[UIImagePickerControllerOriginalImage];
//设置image的尺寸
CGSize imagesize = imageNew.size;
imagesize.width = imageNew.size.width * 0.45;
imagesize.height = imageNew.size.height *0.45;
//对图片大小进行压缩--
//&n