iOS UIImagePickerController,设置框架

我试图完成以下结果:

设置我的UIImagePickerController框架,可以说200 x 200,

设置我的框架在右下angular(就像Facetime / Skype一样)

并显示前/后(无所谓)相机stream。

这是我的代码,出于某种原因,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]; 
  1. 我看过类似的SO主题,但他们都谈论如何

    在UIImagePickerController之上设置视图,而不是我的问题。

  2. 我已经尝试添加self.picker到一个自定义UIView大小200×200但仍然

    没有成功。

我在这里做错了什么?

谢谢

您需要使用UIImagePickercameraViewTransform属性来调整其相机框架。 这个属性接受你所做的任何CGAffineTransform (例如缩放,旋转,翻转,翻译等)。

例如,如果要将摄像机视图向下移动50个点,并将摄像机视图缩放为其原始大小的1.2倍,则可以这样做:

  CGAffineTransform transform = CGAffineTransformMakeTranslation(0.0f, 50.0f); transform = CGAffineTransformScale(transform, 1.2f, 1.2f); imagePicker.cameraViewTransform = transform; 

从UIViewController参考链接

presentViewController:animation:完成:

讨论

在iPhone和iPod touch上,所呈现的视图始终为全屏

如果你想embedded图像select器,你应该手动添加其视图到其他视图之一。

喜欢这个

 [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];