创建自定义UIImagePickerController

时间:2014-03-22 05:03:09

标签: ios objective-c uiimage uiimagepickercontroller

我想尝试创建一个自定义的UIImagePickerController,它有自己的控件,我计划在iPad视图中制作。

我已经开始准备一个UIView,我可以加载我的选择器,但它不起作用;当我调用它的方法时,没有任何反应。

这是我的代码看起来像

UIView *cameraView = [[UIView alloc] initWithFrame:CGRectMake(100, 100, 500, 300)];
[self.view addSubview:cameraView];

UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.delegate = self;
[cameraView addSubview:picker.view];

[self presentViewController:picker animated:YES completion:NULL];

1 个答案:

答案 0 :(得分:0)

让我们尝试以下cameraOverlayView选项来自定义相机屏幕,

示例:

-(void)takePhoto
{       
    if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) 
    {
        cameraPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;

             cameraPickerController.delegate = self;

         cameraPickerController.cameraOverlayView = [self getCameraToolBarWithAnimation:NO];

         cameraPickerController.showsCameraControls = NO;

             [self presentModalViewController:cameraPickerController animated:NO];

    }
    else
    {
        // Photo Library
    }

}

-(UIView *)getCameraToolBarWithAnimation:(BOOL)isAnimat
{
    UIView * fullView = [[[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] autorelease];

    fullView.backgroundColor = [UIColor clearColor];

    if (isAnimat)
    {
        UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 53.5, 320, 320)];

        view.backgroundColor = [UIColor whiteColor];

        [fullView addSubview:view];

        [self performSelector:@selector(shutterHide:) withObject:view afterDelay:0.25];

        [view release];
    }

    UIView * view = [[UIView alloc] initWithFrame:CGRectMake(0, 373.5, 320, 106.5)];

    view.backgroundColor = [UIColor blackColor];

    UIImageView * imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 53.5, 320, 53)];

    imageView.image = [UIImage imageNamed:@"capturetoolbar.png"];

    imageView.userInteractionEnabled = YES;

    CGPoint points[] = {CGPointMake(12, 55),CGPointMake(111, 100),CGPointMake(254, 55)};

    for (int i = 0; i < 3; i++)
    {
        UIButton * cameraButton = [UIButton buttonWithType:UIButtonTypeCustom];

        cameraButton.frame = CGRectMake(points[i].x, 7, points[i].y, 39);

        cameraButton.tag = i;

        [cameraButton addTarget:self action:@selector(cameraOptions:) forControlEvents:UIControlEventTouchUpInside];

        [imageView addSubview:cameraButton];
    }

    [view addSubview:imageView];

    UIView * topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 53.5)];

    topView.backgroundColor = [UIColor blackColor];

    [fullView addSubview:topView];

    [fullView addSubview:view];

    [topView release];

    [view release];

    [imageView release];

    return fullView;
}

-(void)shutterHide:(UIView *)view
{
    [view retain];

    [UIView beginAnimations:nil context:view];

    [UIView setAnimationDuration:1.0];

    [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];

    [UIView setAnimationDelegate:self];

    [view removeFromSuperview];

    [UIView commitAnimations];

    [view release];
} 

谢谢!