我有以下代码将扫描仪框图像放在Zbar的扫描区域周围:
-(UIView *)myOverlay
{
float width = [[UIScreen mainScreen] bounds].size.width;
float height = [[UIScreen mainScreen] bounds].size.height;
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0,0,width,height)];
float imgX = 0;//width*0.12;
float imgY = height*0.25;
float imgW = width;
float imgH = height*0.50;
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(imgX,imgY,imgW,imgH)];
[FrameImg setImage:[UIImage imageNamed:@"scan_box_t.png"]];
[FrameImg setAutoresizingMask:UIViewAutoresizingFlexibleTopMargin | UIViewAutoresizingFlexibleBottomMargin];
[view addSubview:FrameImg];
//view.autoresizesSubviews = true;
return view;
}
问题是,当我旋转iPhone时,此方法生成的叠加视图不会将图像移动到屏幕中心。我通过搜索解决方案找到的自动调整大小的掩模似乎没有什么区别。图像朝向正确的方向 - 但是与屏幕左侧对齐,而不是居中。我该怎么办?
编辑:见下文:
http://speedy.sh/dj8Sw/IMG-L.jpg
http://speedy.sh/EbqC4/IMG-P.jpg
IMG-L是横向,另一个是肖像。肖像一是它应该如何看待从屏幕宽度和高度的25%开始的图像,图像本身的宽度和高度为屏幕的50%。
编辑2:在轮换时执行的代码:
-(void) willRotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
duration:(NSTimeInterval)duration
{
//reader.cameraOverlayView.bounds.size = [[UIScreen mainScreen] bounds].size;
//reader.readerView willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
//[reader.readerView setNeedsLayout];
[reader.cameraOverlayView.FrameImg removeFromSuperview];
}