这个问题与此处提出的现有问题非常相似UIImagePickerControllerCameraDeviceFront 仅在我尝试提出的解决方案时每隔一次才有效,但它对我不起作用
我有一个最简单的项目,有两个视图控制器。在蓝色中,我正在显示一个带有 UIImagePickerController 的小型 UIView。注意:启动应用程序时,我正在显示前置摄像头。
我点击下一个按钮并转到橙色视图控制器,当我点击后退按钮并返回蓝色视图控制器时,UIImagePickerController 从前翻转到后。我想原因是它认为它很忙并移动到后凸轮。如果我继续在视图控制器之间来回移动,相机会不断地前后翻转……
这是我的代码和屏幕截图,我做错了什么?
在我的 *.h
#import <UIKit/UIKit.h>
@interface v1ViewController : UIViewController <UIImagePickerControllerDelegate>
{
UIImagePickerController *picpicker;
UIView *controllerView;
}
@property (nonatomic, retain) UIImagePickerController *picpicker;
@property (nonatomic, retain) UIView *controllerView;
@end
在我的 *.m 文件中(此代码仅在显示蓝色视图控制器时使用)
#import "v1ViewController.h"
#import <MobileCoreServices/UTCoreTypes.h>
@implementation v1ViewController
@synthesize picpicker;
@synthesize controllerView;
- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
#pragma mark - View lifecycle
- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}
- (void)viewDidUnload
{
[super viewDidUnload];
// Release any retained subviews of the main view.
// e.g. self.myOutlet = nil;
}
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
}
- (void)viewDidAppear:(BOOL)animated
{
[super viewDidAppear:animated];
picpicker = [[UIImagePickerController alloc] init];
picpicker.delegate = self;
picpicker.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
picpicker.sourceType = UIImagePickerControllerSourceTypeCamera;
picpicker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picpicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
picpicker.showsCameraControls = NO;
picpicker.navigationBarHidden = NO;
picpicker.wantsFullScreenLayout = NO;
controllerView = picpicker.view;
[controllerView setFrame:CGRectMake(35, 31, 250, 250)];
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(1.0, 1.0);
[self.view addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.alpha = 1.0;
}
completion:nil
];
}
- (void)viewWillDisappear:(BOOL)animated
{
[super viewWillDisappear:animated];
[picpicker dismissModalViewControllerAnimated:YES];
}
- (void)viewDidDisappear:(BOOL)animated
{
[super viewDidDisappear:animated];
[picpicker dismissModalViewControllerAnimated:YES];
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// Return YES for supported orientations
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPhone) {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
} else {
return YES;
}
}
@end