我正在尝试使用自定义UIImagePickerController
对cameraOverlayView
进行编程。当我调用takePicture
的{{1}}方法时,UIImagePickerController
会更改为白色屏幕而不是选择器,您可以在其中选择"使用照片"。如何将后续UIView
设置为选择器而不是空白UIView
?
我在下面提供了我的代码:
UIView
编辑:我修改了我的代码以包含此内容,我仍然得到空白的UIView:
- (void)viewDidLoad
{
[super viewDidLoad];
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(applicationDidBecomeActive)
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}
-(void)dealloc
{
[[NSNotificationCenter defaultCenter] removeObserver:self
name:UIApplicationDidBecomeActiveNotification
object:nil];
}
- (void)applicationDidBecomeActive
{
//Start the camera up
_imageViewPickerController = [[UIImagePickerController alloc] init];
//Hide default UI elements
_imageViewPickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
_imageViewPickerController.showsCameraControls = NO;
_imageViewPickerController.navigationBarHidden = YES;
_imageViewPickerController.toolbarHidden = YES;
//Start the button overlay
UIView *btnView = [[UIView alloc] initWithFrame:_imageViewPickerController.view.bounds];
btnView.opaque = NO;
btnView.clipsToBounds = YES;
//Start up the button
UIButton *snapButton = [[UIButton alloc] initWithFrame:CGRectMake(-6, 504, 65, 65)];
snapButton.alpha = 0.5;
snapButton.transform = CGAffineTransformMakeRotation(DEGREES_RADIANS(90));
[snapButton addTarget:self action:@selector(snapThat) forControlEvents:UIControlEventTouchUpInside];
//Set the button's picture
UIImage *snapButtonImage = [UIImage imageNamed:@"Button.png"];
[snapButton setImage:snapButtonImage forState:UIControlStateNormal];
//Add button to the overlay
[btnView addSubview:snapButton];
//Overlay button view
_imageViewPickerController.cameraOverlayView = btnView;
//Fix for iPhone 5 and make fullscreen
CGAffineTransform translate = CGAffineTransformMakeTranslation(0.0, -55.0);
CGAffineTransform scale = CGAffineTransformMakeScale(1.333333, 1.333333);
CGAffineTransform rotate = CGAffineTransformMakeRotation(DEGREES_RADIANS(180));
CGAffineTransform transform = CGAffineTransformConcat(translate, scale);
transform = CGAffineTransformConcat(transform, rotate);
_imageViewPickerController.cameraViewTransform = transform;
//Let's present it all
[self presentViewController:_imageViewPickerController
animated:NO
completion:NULL];
}
- (void)snapThat {
[_imageViewPickerController takePicture];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
// Save photo
NSString *mediaType = [info objectForKey:UIImagePickerControllerMediaType];
if ([mediaType isEqualToString:(NSString *)kUTTypeImage])
{
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
UIImageWriteToSavedPhotosAlbum(image,nil,nil,nil);
}
[picker dismissViewControllerAnimated:YES completion:NULL];
}
这不是保存图片并将我返回相机视图吗?
答案 0 :(得分:0)
当我调用UIImagePickerController的takePicture方法时,UIView变为白色屏幕而不是选择器,您可以选择"使用Photo"。
这样做是因为你正在dismissViewControllerAnimated:
实施中调用didFinishPickingMediaWithInfo:
。如果您不想取消相机界面,请不要将其解雇。
您没有获得任何自动第二视图(您可以在其中选择"使用照片"或其他)。如果你想要,你必须创建自己的第二个视图控制器并将其推送到UIImagePickerController(这是一个导航控制器)。