我想在我的视图控制器加载时启动相机。我尝试在viewdidload中调用takePhoto方法,但没有任何反应,我做错了什么?我收到以下错误消息: "尝试显示其视图不在窗口层次结构中!" 当我检查元素UIImagePickerController时,它是零...有趣的是,我可以放置一个调用此方法的按钮,当我点击按钮它工作正常,但不是当我在视图中调用它时加载...
- (IBAction)takePhoto {
UIImagePickerController *uiipc=[[UIImagePickerController alloc]init];
uiipc.delegate=self;
uiipc.mediaTypes=@[(NSString *)kUTTypeImage];
uiipc.sourceType=UIImagePickerControllerSourceTypeCamera|UIImagePickerControllerSourceTypePhotoLibrary;
uiipc.allowsEditing=YES;
[self presentViewController:uiipc animated:YES completion:NULL];
}
答案 0 :(得分:0)
试试这个:从视图中调用相机确实出现方法:
// makeCameraOff= YES; call this in didFinishPickingMediaWithInfo method
-(void)viewDidAppear:(BOOL)animated{
if (makeCameraOff==NO){
[self performSelector:@selector(takePic) withObject:nil afterDelay:0];
}
}
-(void)takePic{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate =self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:nil];
}