gpt4 book ai didi

ios - 无法弹出 UIImagePickerController

转载 作者:行者123 更新时间:2023-12-01 18:11:22 25 4
gpt4 key购买 nike

我有一个 UIImagePickerController带有自定义叠加层。我正在尝试实现一个取消按钮,它只会弹出 UIImagePickerController .我的设置代码如下:

- (void)tapPhoto {

//setup the picker
self.picker = [[UIImagePickerController alloc] init];
self.picker.delegate = self;
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraDevice=UIImagePickerControllerCameraDeviceFront;
self.picker.showsCameraControls=NO;

self.cameraOverlay = [[CameraOverlay alloc] init];
UIImage *camoverlayImage = self.cameraOverlay.cameraOverlayImage;
UIImageView *camoverlayImageView = [[UIImageView alloc] initWithImage:camoverlayImage];
camoverlayImageView.frame=CGRectMake(0, 0, self.cameraOverlay.previewSize.width , self.cameraOverlay.previewSize.height);

//init the control view
UIView *cameraControls= [[UIView alloc] initWithFrame:CGRectMake(0, 0, [[UIScreen mainScreen] bounds].size.width, [[UIScreen mainScreen] bounds].size.height)];
[cameraControls addSubview:camoverlayImageView];

//Shutter Button
UIButton *button = [[UIButton alloc] init];//70*70
[button setBackgroundImage:[UIImage imageNamed:@"cameraoff"] forState:UIControlStateNormal];
[button setBackgroundImage:[UIImage imageNamed:@"cameraon"] forState:UIControlStateHighlighted];
button.frame = CGRectMake(([[UIScreen mainScreen] bounds].size.width/2)-70/2, [[UIScreen mainScreen] bounds].size.height-70-10, 70 , 70);
[button addTarget:self action:@selector(takePhoto) forControlEvents:UIControlEventTouchUpInside];
[cameraControls addSubview:button];


UIButton *button2 = [[UIButton alloc] init];
[button2 setTitle:@"Cancel" forState:UIControlStateNormal];
[button2 addTarget:self action:@selector(cancelPhoto) forControlEvents:UIControlEventTouchUpInside];
button2.frame = CGRectMake(5, [[UIScreen mainScreen]bounds].size.height-30, 0, 0);
[button2 sizeToFit];
[cameraControls addSubview:button2];

[self.picker setCameraOverlayView:cameraControls];
[self presentViewController:self.picker animated:YES completion:NULL];

}

-(void)cancelPhoto{

NSLog(@"photo canceled");
[self.navigationController pushViewController:self.picker animated:YES];



}

-(void)takePhoto{
//this will auto trigger the control
[self.picker takePicture];
}

我试图从导航 Controller 中弹出它,但没有任何运气。我也试过 [self.picker popViewControllerAnimated:YES]; .谁能给我任何关于为什么这不起作用的指示?谢谢

最佳答案

您正在(正确地)展示您的选择器:

[self presentViewController:self.picker animated:YES completion:NULL];
present 的反义词不是 push 或 pop,而是 dismiss :
[self dismissViewControllerAnimated:YES completion:nil];

关于ios - 无法弹出 UIImagePickerController,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30530219/

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