UIImagePickerController in TabBarController

僤鯓⒐⒋嵵緔 提交于 2019-12-12 02:24:36

问题


I am trying to implement the imagepickercontroller inside a UITabBarController. So far, so good....

In my ViewController, where I initiate the imagePickerController and then place in my TabBarViewController tabbar array, I implemented the "loadview" method:

- (void)loadView{
    self.arController = [[IFAugmentRealityController alloc] initWithViewController:self];
    [self showCamera];
    [self initOverlayController];
    self.picker.delegate = self;
    [self.view addSubview:self.picker.view];

}

- (void)initOverlayController {
    overlay = [[IFAROverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
    overlay.delegate = self;    
}

- (void)showCamera {
    self.picker = [[UIImagePickerController alloc] init];
    self.picker.navigationBarHidden = YES;
    self.picker.toolbarHidden = YES;
    self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
    self.picker.showsCameraControls = NO;
    self.picker.cameraViewTransform = CGAffineTransformScale(self.picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
    self.picker.cameraOverlayView = overlay;
}

But when I run the app, the app seems to create an inifite loop within the loadView method, and the tabbar does not react anymore. Did I miss something out?

I do not want the ImagePickerController to be fullscreen and pushed with the "presentviewcontroller" method, but loaded as a "normal" view inside one of the tabs.

So my questions are:

1) should I rather use "viewdidload" instead of "loadview"? Because with viewdidload it seems to be working

2) But when using viewdidload I can't fix the frame in which the imagepicker should be shown. There is always a black bar under the video screen and above the tabBar.

Thanks a lot!!


回答1:


I think the infinite loop is coming in when you send the -addSubview message to self.view before setting the view itself with something like self.view = [[UIView alloc] initWithFrame:someFrame]; because, technically, while in loadView you're supposed to be setting the view controller's view.

If self.view is nil and you try to send it messages, -loadView is called again, resulting in the infinite loop.



来源:https://stackoverflow.com/questions/15010105/uiimagepickercontroller-in-tabbarcontroller

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!