我有一个应用程序可以加载相机并覆盖按钮以进行点火,重新加载和返回,以及在点击点火和重新加载按钮时动画的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
答案 0 :(得分:10)
像往常一样创建视图控制器和xib,然后将其添加到您的代码中:
YourOverlay* overlay = [[YourOverlay alloc] initWithNibName:@"YourOverlayView" bundle:nil];
picker.cameraOverlayView = overlay.view;
[picker setDelegate:overlay];
[self presentModalViewController:picker animated:YES];
叠加层必须实施UIImagePickerControllerDelegate
和UINavigationControllerDelegate
答案 1 :(得分:2)
picker.cameraOverlayView = someViewController.view;