0

我正在尝试设置一个包含 UIImagePickerControllerView 顶部按钮的视图。我已经看到可以构建一个overlayView 视图设置picker.showsCameraControls = NO;并将子视图添加到Overlay。但我不想丢失控制器,只是在顶部添加一个按钮。这可能吗?

这是我的代码:

if ([UIImagePickerController isSourceTypeAvailable: UIImagePickerControllerSourceTypeCamera])
{
    UIImagePickerController *imagePickerCam =
    [[UIImagePickerController alloc] init];
    imagePickerCam.delegate = self;
    imagePickerCam.sourceType =
    UIImagePickerControllerSourceTypeCamera;
    imagePickerCam.mediaTypes = [NSArray arrayWithObjects:
                                 (NSString *) kUTTypeMovie,
                                 nil];
    imagePickerCam.allowsEditing = NO;

    UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
    UIButton *Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
    [Button setFrame:CGRectMake(200, 480, 80, 80)];
    [Button addTarget:self action:@selector(action:) forControlEvents:UIControlEventTouchUpInside];
    [overlayView addSubview:Button];

    [imagePickerCam.view addSubview:overlayView];
    [overlayView bringSubviewToFront:imagePickerCam.view];

    [self presentModalViewController:imagePickerCam
                            animated:YES];
}

我正在尝试这个:

 [imagePickerCam.view addSubview:overlayView];
 [overlayView bringSubviewToFront:imagePickerCam.view];

当然,它不起作用。任何想法?

4

1 回答 1

0

首先,你应该使用:

[imagePickerCam setCameraOverlayView: overlayView];

这样,您不必管理子视图的顺序,因此您可以删除该行:

[overlayView bringSubviewToFront:imagePickerCam.view];

顺便说一句,应该是相反的:

[imagePickerCam.view bringSubviewToFront:overlayView];

其次,您的叠加视图的高度为 480,您将 UIButton y 偏移设置为 480,因此按钮超出范围。尝试类似:

UIView *overlayView = [[UIView alloc] initWithFrame:self.view.frame];
UIButton *Button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[Button setFrame:CGRectMake(200, self.view.frame.size.height - 80, 80, 80)];
于 2014-04-16T18:56:35.013 回答