是否可以更改UIImagePickerController的可显示帧大小?我想显示摄像机视图,但不是在整个屏幕上,而是在100x100的边框中显示。
这是我的viewDidAppear:
- (void) viewDidAppear:(BOOL)animated {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.cameraDevice = UIImagePickerControllerCameraDeviceFront;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
[self presentModalViewController:picker animated:YES];
[super viewDidAppear:YES];
}
我找不到办法在任何地方这样做......没有人使用它吗?
答案 0 :(得分:13)
我尝试了上一篇文章中的代码,并评论了最终的缩放变换((使其成为全尺寸的变换)并且我最终得到了一个可爱的微型相机imagePicker漂浮在我的屏幕中间,所以它绝对有用!我使用的确切代码,包括缩放/淡入过渡,是 -
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
UIView *controllerView = imagePickerController.view;
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);
[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.alpha = 1.0;
}
completion:nil
];
[imagePickerController release];
我相信你可以更多地定制它,改变尺寸和尺寸。摄像机视图的位置。
答案 1 :(得分:3)
如果你想在UIImagePickerController的顶部显示一个叠加层,例如在我的情况下,同时在你的叠加层上的某些UI组件之间安装控制器的“实时摄像机输入”(视图)(例如顶栏和底栏),使用以下代码。这是基于SomaMan上面的答案(谢谢),主要区别在于将UIImagePickerController的视图显示为当前控制器的子视图而不是主应用程序窗口的子视图。将此代码放在viewDidLoad()中:
// Overlay view with custom camera controls and a top bar and a bottom bar
self.overlay = [[CameraOverlayView alloc] initWithFrame:self.view.bounds];
[self setOverlayViewModel];
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.imagePicker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.imagePicker.cameraFlashMode = UIImagePickerControllerCameraFlashModeOff;
self.imagePicker.showsCameraControls = NO;
self.imagePicker.navigationBarHidden = YES;
self.imagePicker.toolbarHidden = YES;
self.imagePicker.delegate = self;
UIView *imagePickerView = self.imagePicker.view;
if ([[UIScreen mainScreen] bounds].size.height == 568.0f) {
// iPhone 5, 16:9 ratio, need to "zoom in" in order to fill the screen since there is extra space between top and bottom bars on a taller screen
self.imagePicker.cameraViewTransform = CGAffineTransformScale(self.imagePicker.cameraViewTransform, 1.5, 1.5); // change 1.5 to suit your needs
}
CGRect cameraViewFrame = CGRectMake(0, self.overlay.topBarHeight,
self.view.bounds.size.width,
self.view.bounds.size.height - self.overlay.topBarHeight - self.overlay.bottomBarHeight);
imagePickerView.frame = cameraViewFrame;
// keep this order so that the overlay view is on top of the "live camera feed" view
[self.view addSubview:imagePickerView];
[self.view addSubview:self.overlay];
提示:执行cameraViewTransform时,如果您希望用户最终获得他们通过转换的选择器视图看到的相同图像,请确保对所选照片执行相同的转换,以便选择器捕获:P
答案 2 :(得分:1)
我有时直接添加了ImagePicker的视图,虽然我从未尝试过更改其最终大小,但它会“缩放”到屏幕上,这表明它可以以不同的大小显示(代码直接提升)来自我的一个项目,所以可能并非全部相关) -
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
UIView *controllerView = imagePickerController.view;
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);
[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.transform = CGAffineTransformMakeScale(1.0, 1.0);
controllerView.alpha = 1.0;
}
completion:nil
];
[imagePickerController release];
有兴趣看看你是否得到任何结果。