只是想知道当用户点击按钮时,是否有人可以帮助我识别和创建这样的iOS选项(http://imgur.com/QSfYavr),它可以选择使用相机或从照片库中选择图片。我已经研究过UIIMAGEPICKER,但不要认为这就是我所追求的。
我正在使用最新的Xcode + iOS 7开发。
感谢。
答案 0 :(得分:0)
您可以使用以下代码:
// Set these delegates in the header file
<UIImagePickerControllerDelegate, UINavigationControllerDelegate,UIActionSheetDelegate>
// On Button Action
UIActionSheet *actionSheet = [[UIActionSheet alloc] initWithTitle:@"Select Face for Perform Dance step"
delegate:self
cancelButtonTitle:@"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:@"Camera", @"Select from Library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackTranslucent;
[actionSheet showInView:self.view];
//行动表委托
#pragma mark -
#pragma mark UIActionSheetDelegate
- (void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
int i = buttonIndex;
switch(i)
{
case 0:
{
UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:^{}];
}
break;
case 1:
{
UIImagePickerController * picker = [[[UIImagePickerController alloc] init] autorelease];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:picker animated:YES completion:^{}];
}
default:
// Do Nothing.........
break;
}
}
最后处理相机并从图库操作中选择:
#pragma mark -
#pragma - mark Selecting Image from Camera and Library
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Picking Image from Camera/ Library
[picker dismissViewControllerAnimated:YES completion:^{}];
self.selectedImage = [info objectForKey:@"UIImagePickerControllerOriginalImage"];
if (!self.selectedImage)
{
return;
}
// Adjusting Image Orientation
NSData *data = UIImagePNGRepresentation(selectedImage);
UIImage *tmp = [UIImage imageWithData:data];
UIImage *fixed = [UIImage imageWithCGImage:tmp.CGImage
scale:selectedImage.scale
orientation:self.selectedImage.imageOrientation];
self.selectedImage = fixed;
}
此代码适用于所有iOS SDK 5.x,6.x,7.x. 请享用。 :)
答案 1 :(得分:0)
iOS7的UIActionSheet
,如果您更新iOS7应用程序,则会查找iOS7之前的所有iOS版本,这是已经制作的版本,您可以查看,https://github.com/ianb821/IBActionSheet