UIImagePickerController在缩放时显示黑条 – 这是iOS中的错误吗?
编辑 : 有人build议这个post是重复的 ,情况并非如此,因为黑色条纹最初不存在,仿制转换不能解决问题。
我在iPad Air 2上运行这个和目标iOS 8.我有一个UIImagePickerController
其showsCameraControls
属性设置为NO
。 当在横向启动应用程序,然后放大,这是发生了什么(所有的图像是非裁剪):
出现黑条,可以通过将设备方向更改为纵向(也将显示黑条)并将其更改回来。
改为肖像之后:
回到风景(+放大):
奇怪的是,在回到风景之后,缩放滑块在缩放过程中不再可见。 从最初的肖像开始,缩放首先工作,直到一个更改为横向,其中出现一个黑色的酒吧,其中返回到肖像时停留。
将showsCameraControls
设置为YES
时,不会发生这种情况。 我怎样才能摆脱这个问题?
更新 :苹果宣称已经解决了这个问题在iOS 9。
我find了一种方法来解决我缺乏更好的理解会标记一个错误(就像苹果提供的示例一样)。
我的解决scheme是做手动缩放,通过添加一个UIPinchGestureRecognizer
覆盖视图。 然后控制器必须执行缩放callback,这将消除上述现象。
@implementation CameraViewController { CGFloat _lastScale; //< the current zoom scale before update } - (void)viewDidLoad { [super viewDidLoad]; self.imagePicker = [[UIImagePickerController alloc] init]; self.imagePicker.delegate = self; self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera; self.imagePicker.allowsEditing = NO; self.imagePicker.showsCameraControls = NO; [[NSBundle mainBundle] loadNibNamed:@"CameraOverlay" owner:self options:nil]; UIPinchGestureRecognizer *pinchRec = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(zoom:)]; [self.overlayView addGestureRecognizer:pinchRec]; self.imagePicker.cameraOverlayView = self.overlayView; _lastScale = 1.; } - (void)zoom:(UIPinchGestureRecognizer *) sender { // reset scale when pinch has ended so that future scalings are applied cumulatively and the zoom does not jump back (not sure I understand this) if([sender state] == UIGestureRecognizerStateEnded) { _lastScale = 1.0; return; } CGFloat scale = 1.0 - (_lastScale - sender.scale); // sender.scale gives current distance of fingers compared to initial distance. We want a value to scale the current transform with, so diff between previous scale and new scale is what must be used to stretch the current transform CGAffineTransform currentTransform = self.imagePicker.cameraViewTransform; CGAffineTransform newTransform = CGAffineTransformScale (currentTransform, scale, scale); // stretch current transform by amount given by sender newTransform.a = MAX(newTransform.a, 1.); // it should be impossible to make preview smaller than screen (or initial size) newTransform.d = MAX(newTransform.d, 1.); self.imagePicker.cameraViewTransform = newTransform; _lastScale = sender.scale; } @end