gpt4 book ai didi

ios - 子类化 UIImagePickerController 以添加功能

转载 作者:可可西里 更新时间:2023-11-01 05:03:16 27 4
gpt4 key购买 nike

基本上我想做的是,将“拍摄图像”按钮更改为我的自定义按钮。当用户改变 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 屏幕。一切都很好。

最佳答案

抱歉,您不能继承 UIImagePickerController。来自文档:

Important: The UIImagePickerController class supports portrait mode only. This class is intended to be used as-is and does not support subclassing. The view hierarchy for this class is private and must not be modified, with one exception. You can assign a custom view to the cameraOverlayView property and use that view to present additional information or manage the interactions between the camera interface and your code.

但是,您可以完全控制拍照 UI。

关于ios - 子类化 UIImagePickerController 以添加功能,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21062327/

27 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com