2014-01-11 96 views
3

所以基本上我想要做的是將「拍攝圖像」按鈕更改爲我的自定義按鈕。 當用戶更改DeviceOrientation時,按鈕將根據方向改變。 我已經嘗試使用「overLay」屬性,但似乎無法更改或移動「overLay」一旦放置。 所以我決定繼承UIImagePickerController,但是當我打電話給它時,相機將不會顯示!用於添加功能的UIImagePickerController子類

任何幫助瞭解問題會有所幫助......謝謝!

這是的viewController調用子類 「的UIImagePickerController」:

@interface CameraViewController : UIViewController<UIImagePickerControllerDelegate> 
@interface CameraViewController() 
@property (nonatomic) pickerControllerMC *cameraPickerView; 

self.cameraPickerView = [[pickerControllerMC alloc]initWithNibName:@"pickerControllerMC"  bundle:nil]; 
self.cameraPickerView.delegate = self; 


// Do any additional setup after loading the view. 
//create a new image picker instance 
//set source to video! 
self.cameraPickerView.sourceType = UIImagePickerControllerSourceTypeCamera; 
//hide all controls 
self.cameraPickerView.showsCameraControls = NO; 
self.cameraPickerView.navigationBarHidden = YES; 
self.cameraPickerView.toolbarHidden = YES; 
// self.delegate = self; 
//make the video preview full size 
self.cameraPickerView.wantsFullScreenLayout = YES; 
self.cameraPickerView.cameraViewTransform = 
CGAffineTransformScale(self.cameraPickerView.cameraViewTransform, 
         CAMERA_TRANSFORM_X, 
         CAMERA_TRANSFORM_Y); 

//Getting WidthAnd hight 
CGRect screen = [[UIScreen mainScreen] bounds]; 
//CGFloat widthInPixel = screen.size.width * scaleFactor; 
//CGFloat heightInPixel = screen.size.height * scaleFactor; 
int Width = screen.size.width; 
int hight = screen.size.height; 

[self presentViewController:self.cameraPickerView animated:YES completion:nil]; 

,這是子類:

@interface pickerControllerMC : UIImagePickerController 

@implementation pickerControllerMC 

    - (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil 
    { 
    self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil]; 
    if (self) { 
     // Custom initialization 
    } 
    return self; 
    } 

    - (void)viewDidLoad 
    { 
    [super viewDidLoad]; 

    UIButton *buttonTakeImage = [UIButton 
         buttonWithType:UIButtonTypeRoundedRect]; 
    [buttonTakeImage setBackgroundImage:[UIImage imageNamed:@"[email protected]"]  forState:UIControlStateNormal]; 

    [buttonTakeImage addTarget:self action:@selector(takePictureClicked)  forControlEvents:UIControlEventTouchUpInside]; 

    [self.view addSubview:self.overlay]; 
    [self.view addSubview:buttonTakeImage]; 


    //Adding orientation Notifications! 
    [[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications]; 
    [[NSNotificationCenter defaultCenter] addObserver: self selector:  @selector(deviceOrientationDidChange:) name: UIDeviceOrientationDidChangeNotification object: nil]; 


    } 

編輯

好我的錯誤是,我用「initWithNibName 「,所以我每次都得到一個白色的筆尖屏幕......都很好。

回答

10

對不起,你不能繼承UIImagePickerController。從文檔:

重要提示:UIImagePickerController類僅支持肖像模式 。本課程旨在按原樣使用,不支持 子類。此類的視圖層次結構是私有的,不得修改 ,但有一個例外。您可以將自定義視圖分配給 cameraOverlayView屬性,並使用該視圖顯示其他 信息或管理相機接口 與您的代碼之間的交互。

但是,您可以完全控制圖片獲取UI。

+0

首先感謝您的回答! – user2904350

+0

首先感謝您的回答!那究竟是什麼意思?我的應用程序與UIImagePickerController的子類完美地工作,它不會被蘋果批准嗎?相機覆蓋的問題,是你添加一個overLay,你不能像我想要做的那樣移動它。我正在製作「TakePic」按鈕,旋轉。 – user2904350

+1

這意味着你不應該子類'UIImagePicker',相反,你的自定義應該在SDK推薦和支持的方法之一中完成。如果你做了'UIImagePicker'的子類,取決於你製作的視圖操作,你可能會很幸運,而且事情會起作用,但如果它們不在你不受支持的領域。 – XJones