xcode 使用视图控制器作为相机覆盖?
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/12225593/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Use a View Controller as a camera overlay?
提问by Dale Townsend
I have an app that loads the camera and overlays buttons for fire, reload, and back, as well as a png that animates when the fire and reload buttons are tapped. How would I load the View Controller, which has a .xib with the buttons and image, as an overlay when the camera view loads?
我有一个应用程序,它加载相机并覆盖开火、重新加载和返回按钮,以及一个在点击开火和重新加载按钮时动画的 png。当相机视图加载时,我将如何加载带有按钮和图像的 .xib 的视图控制器作为叠加层?
I have the camera view loading when a button on the main screen is tapped, which used to open another View with the buttons and gun image.
当点击主屏幕上的按钮时,我会加载相机视图,该按钮用于打开另一个带有按钮和枪图像的视图。
Below is what I have done so far, which is loading the camera. I have a separate View Controller named PlayViewController, with an xib for the interface:
以下是我到目前为止所做的,即加载相机。我有一个名为 PlayViewController 的单独视图控制器,接口有一个 xib:
-(IBAction)getCameraPicture:(id)sender {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
PlayViewController* overlay = [[PlayViewController alloc] initWithNibName:@"PlayViewController" bundle:nil];
picker.cameraOverlayView = overlay.view;
[picker setDelegate:overlay];
[self presentModalViewController:picker animated:YES];
}
This is in the PlayViewController.m: code
这是在 PlayViewController.m 中: code
#import "PlayViewController.h"
#import "SoundViewController.h"
@interface PlayViewController ()
@end
@implementation PlayViewControlleriPad...
`
`
PlayViewController.h:
播放视图控制器.h:
@interface PlayViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
{
two array declarations...
}
@property (weak, nonatomic) IBOutlet UIButton *reloadButton;
@property (weak, nonatomic) IBOutlet UIButton *fireButton;
@property (weak, nonatomic) IBOutlet UITextField *ammoField;
@property (weak, nonatomic) IBOutlet UIImageView *type;
@end
回答by andreamazz
Create your view controller and xib as usual, then add this to your code:
像往常一样创建您的视图控制器和 xib,然后将其添加到您的代码中:
YourOverlay* overlay = [[YourOverlay alloc] initWithNibName:@"YourOverlayView" bundle:nil];
picker.cameraOverlayView = overlay.view;
[picker setDelegate:overlay];
[self presentModalViewController:picker animated:YES];
The overlay must implement UIImagePickerControllerDelegate
and UINavigationControllerDelegate
叠加层必须实施UIImagePickerControllerDelegate
和UINavigationControllerDelegate
回答by andreamazz
picker.cameraOverlayView = someViewController.view;