如何让 iPhone 上的摄像头出现在应用程序委托中?是否可以?
我只是在玩一个打开相机的简单程序。这就是我想做的全部事情。我是一名初学者,我相信我已经掌握了 iPhone 用户界面管理的基础知识,所以我决定尝试一下。
我现在想做的是......
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
UIImagePickerController * camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.allowsEditing = NO;
camera.showsCameraControls = NO;
[viewController presentModalViewController:camera animated:NO];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES:
}
所以基本上,初始化相机,设置一些东西并将其显示在主视图中。我将相机的委托设置为 self,因为此代码放置在委托类中(是的,委托类符合 UIImagePickerControllerDelegate && UINavigationControllerDelegate)。
现在的主要问题是屏幕上什么也没有出现。我完全不知道我做错了什么,特别是因为程序正在正确构建,没有错误或警告......
任何帮助表示赞赏!非常感谢:D
I'm just playing around with a simple program that opens the camera. That's literally all that I want to do. I'm a beginner and I believe that I have the basics down in terms of UI management for the iPhone so I decided to give this one a whirl.
What I'm trying to do right now is...
- (BOOL) application:(UIApplication*) application didFinishLaunchingWithOptions:(NSDictionary*) launchOptions
{
UIImagePickerController * camera = [[UIImagePickerController alloc] init];
camera.delegate = self;
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
camera.allowsEditing = NO;
camera.showsCameraControls = NO;
[viewController presentModalViewController:camera animated:NO];
[window addSubview:viewController.view];
[window makeKeyAndVisible];
return YES:
}
So basically, initialize the camera, set some things and show it in the main view. I set the camera's delegate to self because this code is placed in the delegate class (and yes, the delegate class is conforming to UIImagePickerControllerDelegate && UINavigationControllerDelegate).
Main problem right now is that nothing is appearing on the screen. I have absolutely no idea what I'm doing wrong, especially since the program is building correctly with no errors or warnings...
Any help is appreciated! Thanks a lot :D
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
在将 UIImagePickerController 的视图添加到窗口之前,您正尝试从视图控制器显示 UIImagePickerController。那是行不通的。它必须从已经显示的视图中呈现。
我不确定这是否有效,因为我还没有尝试过,但请切换代码的顺序。首先将视图控制器添加到窗口:
如果这不起作用,请尝试将 UIImagePickerController 代码移动到根视图控制器的 -viewDidLoad(无论代码中的 viewController 是什么)。
You are trying to display the UIImagePickerController from your view controller before you'e added its view to the window. That won't work. It has to be presented from a view that is already displaying.
I'm not absolutely sure this will work as I haven't tried it, but switch the order of your code. Add your view controller to the window first:
If this doesn't work, then try moving your UIImagePickerController code to your -viewDidLoad of your root view controller (whatever viewController is in your code).