-(IBAction)photoClick:(id)sender{
UIActionSheet *actionSheet = [[UIActionSheetalloc]initWithTitle:nildelegate:selfcancelButtonTitle:@"取消"destructiveButtonTitle:nilotherButtonTitles:@"拍照",@"图库", nil];
[actionSheet showInView:self.view];
}
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex{
if (buttonIndex == 0) {//拍照
//资源类型为照相机
UIImagePickerControllerSourceType sourceType = UIImagePickerControllerSourceTypeCamera;
//判断是否有相机
if ([UIImagePickerControllerisSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera]){
UIImagePickerController *picker = [[UIImagePickerControlleralloc] init];
picker.delegate = self;
//资源类型为照相机
picker.sourceType = sourceType;
[selfpresentViewController:picker animated:YEScompletion:nil];
}else {
UIAlertView *alertView = [[UIAlertViewalloc]initWithTitle:nilmessage:@"该设备无摄像头"delegate:selfcancelButtonTitle:@"取消"otherButtonTitles: nil];
[alertView show];
}
}elseif (buttonIndex == 1){//图库
UIImagePickerController *pickerController = [[UIImagePickerControlleralloc] init];
pickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
pickerController.delegate = self;
//设置选择后的图片可被编辑
pickerController.allowsEditing = NO;
[selfpresentViewController:pickerController animated:YEScompletion:nil];
}
}
-(void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
NSString *type = [info objectForKey:UIImagePickerControllerMediaType];
//当选择的类型是图片
if ([type isEqualToString:@"public.image"])
{
UIImage* image = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
UIImageView * tempImage = [[UIImageViewalloc] initWithImage:image];
tempImage.frame = CGRectMake(20+picWidth+20, topImgHeight+timeImgHeight+21, UISCREEN_WIDTH-(20+picWidth+20)-20, UISCREEN_HEIGHT/2-topImgHeight-timeImgHeight-50);
tempImage.userInteractionEnabled = NO;
[self.viewaddSubview:tempImage];
}
[picker dismissViewControllerAnimated:YEScompletion:nil];
}