gpt4 book ai didi

ios - 创建自定义 UIImagePickerController

转载 作者:行者123 更新时间:2023-11-29 03:07:45 49 4
gpt4 key购买 nike

我想尝试创建一个自定义外观的 UIImagePickerController,其中包含我计划在 iPad View 中制作的自己的控件。

我已经开始准备一个 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];

最佳答案

让我们尝试下面的 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];
}

谢谢!

关于ios - 创建自定义 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22573706/

49 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com