我在我正在创建的 iPad 应用程序中使用 zBAR QR 阅读器,并在ZBarReaderViewController
. 我已经设法将覆盖层置于中心,但是当设备旋转时,覆盖层显然会偏离中心。
我已经搜索了有关以编程方式限制视图的方法,但没有任何建议有效。我已经尝试了所有可能的组合,UIViewAutoResizingMask
并且我已经尝试了使用该[NSLayoutConstraint constraintWithItem:attribute:relatedBy:toItem:attribute:multiplier:constant:]
方法的大量不同设置。
这是我的代码:
self.readerqr = [ZBarReaderViewController new];
int readerPointX = ((self.view.bounds.origin.x) + (self.view.bounds.size.width / 2.0));
int readerPointY = ((self.view.bounds.origin.y) + (self.view.bounds.size.height / 2.0) -60);
self.readerqr.readerDelegate = self;
self.readerqr.showsHelpOnFail = NO;
CGRect viewFrame = CGRectMake(readerPointX, readerPointY, 200, 200);
self.crossHair = [[UIImageView alloc] initWithFrame:viewFrame];
self.crossHair.image = [UIImage imageNamed:@"qr.png"];
[self.readerqr setCameraOverlayView:self.crossHair];
constraint = [NSLayoutConstraint constraintWithItem:self.crossHair
attribute:NSLayoutAttributeHeight
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:200];
[self.crossHair addConstraint:constraint];
constraint = [NSLayoutConstraint constraintWithItem:self.crossHair
attribute:NSLayoutAttributeWidth
relatedBy:NSLayoutRelationEqual
toItem:nil
attribute:NSLayoutAttributeNotAnAttribute
multiplier:1
constant:200];
[self.crossHair addConstraint: constraint];
设置它的正确方法是什么,这样我的叠加层将始终位于屏幕中央,无论方向如何变化?任何帮助都会很棒,谢谢。