1

我有一个应用程序可以加载相机并覆盖用于触发、重新加载和返回的按钮,以及一个在点击触发和重新加载按钮时动画的 png。当相机视图加载时,我将如何加载具有按钮和图像的 .xib 的视图控制器作为覆盖?

当点击主屏幕上的按钮时,我会加载相机视图,该按钮用于打开带有按钮和枪图像的另一个视图。

以下是我到目前为止所做的,正在加载相机。我有一个名为 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];

这是在 PlayViewController.m 中:code

   #import "PlayViewController.h"
   #import "SoundViewController.h"

@interface PlayViewController ()

@end

@implementation PlayViewControlleriPad...

`

PlayViewController.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
4

2 回答 2

10

像往常一样创建您的视图控制器和 xib,然后将其添加到您的代码中:

YourOverlay* overlay = [[YourOverlay alloc] initWithNibName:@"YourOverlayView" bundle:nil];
picker.cameraOverlayView = overlay.view;
[picker setDelegate:overlay];
[self presentModalViewController:picker animated:YES];

覆盖必须实现UIImagePickerControllerDelegateUINavigationControllerDelegate

于 2012-09-01T06:58:52.530 回答
2
picker.cameraOverlayView = someViewController.view;
于 2012-09-01T06:57:54.107 回答