问题描述
我正在尝试在UITabBarController内实现imagepickercontroller.到目前为止,很好...
I am trying to implement the imagepickercontroller inside a UITabBarController. So far, so good....
在ViewController中,我启动了imagePickerController,然后将其放置在TabBarViewController tabbar数组中,我实现了"loadview"方法:
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;
}
但是当我运行该应用程序时,该应用程序似乎在loadView方法内创建了一个inifite循环,并且选项卡不再起作用.我错过了什么吗?
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?
我不希望ImagePickerController是全屏显示并使用"presentviewcontroller"方法推送,而是作为其中一个选项卡中的普通"视图加载.
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.
所以我的问题是:
1)我应该使用"viewdidload"而不是"loadview"吗?因为使用viewdidload似乎可以正常工作
1) should I rather use "viewdidload" instead of "loadview"? Because with viewdidload it seems to be working
2)但是,当使用viewdidload时,我无法固定应在其中显示图像选择器的框架.视频屏幕下方和tabBar上方始终有一个黑条.
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.
非常感谢!
推荐答案
我认为在将-addSubview
消息发送给self.view
之前,先使用self.view = [[UIView alloc] initWithFrame:someFrame];
之类的视图设置自身,这时就会出现无限循环,因为,从技术上讲,在loadView
中,您应该设置视图控制器的视图.
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.
如果self.view
是nil
,并且您尝试向其发送消息,则会再次调用-loadView
,从而导致无限循环.
If self.view
is nil
and you try to send it messages, -loadView
is called again, resulting in the infinite loop.
这篇关于TabBarController中的UIImagePickerController的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!