我正在尝试完成以下结果:
将我的UIImagePickerController的框架设置为200 x 200,
将我的框架设置在右下角(就像Facetime / Skype那样)
并显示前/后(无关紧要)相机流。
这是我的代码,出于某种原因,setFrame无效!
self.picker = [[UIImagePickerController alloc] init];
self.picker.sourceType = UIImagePickerControllerSourceTypeCamera;
self.picker.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
self.picker.cameraDevice = UIImagePickerControllerCameraDeviceRear;
self.picker.showsCameraControls = NO;
self.picker.navigationBarHidden = YES;
self.picker.view.frame = CGRectMake(600, 400, 200, 200); // NOT WORKING !!!
self.picker.toolbarHidden = YES;
self.picker.wantsFullScreenLayout = NO;
self.picker.delegate = delegate;
[self presentViewController:self.picker animated:YES completion:nil];
我看过类似的SO主题,但他们都在谈论如何
在UIImagePickerController上设置一个视图,而不是我的问题。
我尝试将self.picker添加到尺寸为200 x 200的自定义UIView中,但仍然
没有成功。
我在这里做错了什么?
由于
答案 0 :(得分:5)
您需要使用cameraViewTransform
的{{1}}属性来调整其相框。此属性接受您所做的任何UIImagePicker
(例如缩放,旋转,反转,翻译等)。
例如,如果您想将摄像机视图向下移动50个点并将摄像机视图缩放1.2倍其原始大小,那么您就是这样做的:
CGAffineTransform
答案 1 :(得分:2)
来自UIViewController参考link
<强> presentViewController:动画:完成:强>
<强>讨论强>
在iPhone和iPod touch上,呈现的视图始终为全屏
如果您想嵌入图片选择器,则应手动将其视图添加到其他视图中。
像这样[self.view addSubview:self.imagePickerController.view];
我尝试了上一篇文章中的代码,并评论了最终的缩放变换((使其成为全尺寸的变换)并且我最终得到了一个可爱的微型相机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];