iOS 4.3 上的cameraOverlayView 问题
我使用带有cameraOverlayView的选择器控制器在相机视图中显示产品的图像。在应用到覆盖层之前,产品图像会调整大小。 它在 iOS 4.2 上运行良好,但在 iOS 4.3 上产品图像显示为全尺寸。
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
我更改了用作叠加层的 UIImageView 的框架,但它仍然以 320*480 显示。 我知道 CameraOverlayView 在 iOS 4.3 中已被修改,但我不知道发生了什么变化以及我必须做什么来纠正我的应用程序。
感谢您的帮助。
I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay.
It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480.
I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.
Thanks for your help.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(5)
在 iOS 4.3 中,覆盖视图被拉伸至全屏。由于您将内容模式设置为宽高比,因此图像会拉伸以适应新的视图尺寸(320x480)。
您需要创建一个全屏的透明 UIView,将 imageview 添加到该视图并使 UIView 成为新的覆盖视图。
In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.
You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.
发现这篇文章似乎符合要求。长短都是用
Found this article that seems to fit the bill. The long and short of it is to use
注释掉代码中的这一行
它应该可以工作。
如果你真的想剪辑,@slf 的回答应该有帮助。
Comment out this line in your code
It should work.
If you really want to clip, @slf 's answer should help.
尝试设置 UIImagePicker 的这些属性:
try setting these properties of
UIImagePicker
:我的问题实际上是,在 iOS5 上全屏显示的 UIImagePicker 在 iPad 上的 iOS4.3 上不起作用。我在屏幕外启动图像拾取器,然后将其动画化到视图中...您会看到快门图像打开,但相机视图本身是透明的,没有相机输出。
我的解决方案是在 iPad 上的 iOS4.3 中不设置动画。似乎让相机视图在屏幕外启动会将相机渲染部分抛在后面(正如我在 iOS5 中指出的那样,已修复)。
这个答案对于原来的问题来说不太正确,但我把它放在这里是为了那些遇到同样问题并像我一样遇到这个问题的人。
My problem was actually that a UIImagePicker displayed full-screen on iOS5 did not work on iOS4.3, on an iPad. I was starting the image picker up offscreen, then animating it into view... You would see the shutter image open up, but then the camera view itself was simply transparent with no camera output.
My solution was to not animate that in for iOS4.3 on the iPad. It seems that having the camera view started offscreen was leaving the camera rendering part behind (fixed as I noted in iOS5).
This answer is not quite right for the original question but I place it here for someone that comes into the same issue and hits this question as I did.