2

我正在使用滑动菜单,就像您在 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];
}
4

1 回答 1

1

解决它的一种快速方法是在您呈现选择器时隐藏主 ViewController,并在它被关闭后再次显示它。假设您有对主 ViewController 的引用,只需将其view.hidden属性设置为 YES。

处理它的另一种方法是从主 ViewController 而不是后菜单显示它。

于 2013-04-03T00:23:29.630 回答