另一种处理它的方法是从主视图控制器中呈现它,而不是从后菜单。
我正在使用滑动菜单,就像你在Facebook或Path应用程序中看到的那样。
在后面的菜单中,我想允许用户通过使用相机或照片库添加图像。
我遇到的问题是主视图控制器,我滑动的那个,总是在顶部。
动作表显示得很好,但是模态视图控制器被主视图控制器部分隐藏了。
这是我的选择器代码:
- (void)viewDidLoad
{
[super viewDidLoad];
_UIPicker = [[UIImagePickerController alloc] init];
_UIPicker.delegate = self;
}
- (IBAction)profilePicButtonTapped
{
UIActionSheet * actionSheet = [[UIActionSheet alloc] initWithTitle:@"Set Up Your Profile Picture" delegate:self cancelButtonTitle:@"Cancel" destructiveButtonTitle:nil otherButtonTitles:@"Camera", @"Photo Library", nil];
actionSheet.actionSheetStyle = UIActionSheetStyleBlackOpaque;
[actionSheet showInView:_rearTableView];
}
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex
{
if (buttonIndex == 0)
{
_UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:_UIPicker animated:YES completion:nil];
}
else if (buttonIndex == 1)
{
_UIPicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentViewController:_UIPicker animated:YES completion:nil];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:@"Error" delegate:self cancelButtonTitle:@"Cancel" otherButtonTitles:nil];
[alert show];
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage * selectedImage = [info objectForKey:UIImagePickerControllerOriginalImage];
_profileImageView.image = selectedImage;
[self dismissViewControllerAnimated:YES completion:nil];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
[picker dismissViewControllerAnimated:YES completion:nil];
}
解决这个问题的一个快速方法是在呈现选择器时隐藏主视图控制器,并在它被取消时再次显示它。假设你有一个对主视图控制器的引用,只需将它的view.hidden
属性设置为YES。