子类化UIImagePickerController以添加功能

时间:2014-01-11 12:39:19

标签: ios iphone objective-c ios7 uiimagepickercontroller

所以基本上我要做的是,将“拍摄图像”的按钮更改为我的自定义按钮。 当用户更改DeviceOrientation时,按钮将根据方向改变。 我已经尝试过使用“overLay”属性,但是一旦放置它就似乎无法改变或移动“overLay”。 所以我决定继承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:@"CameraButton@2x"]     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”,所以我每次都有一个白色的Nib屏幕..一切都很好。

2 个答案:

答案 0 :(得分:12)

抱歉,您无法继承UIImagePickerController。来自文档:

  

重要说明:UIImagePickerController类支持纵向模式   只要。此类旨在按原样使用,不支持   子类。此类的视图层次结构是私有的,不得使用   被修改,但有一个例外。您可以为自定义视图分配   cameraOverlayView属性并使用该视图来显示其他内容   信息或管理相机界面之间的交互   和你的代码。

但是,您可以完全控制拍摄UI的图片。

答案 1 :(得分:0)

可以对var x = document.getElementById("username").value; 进行子类化,以添加属性以传递给UIImagePickerController方法。我做到了没有任何问题。但是人们无法使用它的方法或视图。