2012-09-01 72 views
1

我有一個應用程序,加載相機和覆蓋按鈕的火災,重新加載和返回,以及一個PNG,當點火和重新加載按鈕時動畫。如何在加載攝像機視圖時將視圖控制器(它帶有按鈕和圖像的.xib)加載爲覆蓋圖?使用視圖控制器作爲攝像頭覆蓋?

當主屏幕上的一個按鈕被點擊時,我有相機視圖加載,用於打開另一個按鈕和槍圖像的視圖。

以下是我迄今爲止所做的,即加載相機。我有一個單獨的視圖控制器命名PlayViewController,與該接口的廈門國際銀行:

-(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 

回答

10

創建視圖控制器和廈門國際銀行像往常一樣,然後添加到您的代碼:

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

的覆蓋必須實現UIImagePickerControllerDelegateUINavigationControllerDelegate

+0

這樣做會給我一個[picker] setDelegate:overlay]錯誤。如下所示:'將'PlayViewControlleriPad * _strong發送到不兼容類型的參數'id ' –

+2

覆蓋層必須實現這些協議。 @interface YourOverlay:UIViewController andreamazz

+0

我已經實現了這些協議,它仍然給我警告。除非這兩件事的順序? –

2
picker.cameraOverlayView = someViewController.view; 
+1

我想這一點,但它給我的錯誤:「物業在'PlayViewController'類型的對象上找不到'view'。有什麼我需要添加到PlayViewController? –

+0

@DaleTownsend你確定你的PlayViewController真的是一個視圖控制器嗎? – 2012-09-01 07:17:28

+0

它應該是,它有一個.m,.h和接口的xib。在.h文件中,#import語句後有@interface PlayViewController:UIViewController。 –