我目前正在开发一个使用 ZBarSDK 读取二维码的 iPad 应用程序。
我正在使用 ZBarReaderView
(不是 UIViewController
),所以我在 UIView
中显示前置摄像头,它是使用 CGRect
(见下面的代码)。
我的问题是相机出现在 View 中的一侧。 iPad 应用程序将仅开发为在横向模式下工作。
当 UIView
现在出现时,图像在它的一侧,我不确定如何修复它。我尝试使用 CGAffineTransform
成功地稍微改变了角度,但是如果 iPad 以另一种方式翻转,这将如何处理?
我看到了一些关于这个类似问题的其他帖子,但没有对我有用的解决方案。值得注意的是我使用的是 IOS6,请记住我使用的是 ZBarReaderView
,因此 supportedOrientationsMask
不可用。
我希望用户在直立位置看到相机 View ,无论横向是左侧还是右侧。不过现在,无论转向哪个方向,视频都是横向的(所以我可以看到自己与侧面成 90 度角)。 UIView
也不会在屏幕转动时发生任何变化。我有点迷路了。
代码:
- (void) viewDidAppear: (BOOL) animated {
ZBarReaderView * readerView = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
[readerView initWithImageScanner:scanner];
readerView.readerDelegate = self;
readerView.tracksSymbols = YES;
readerView.frame = CGRectMake(20,220,230,230);
readerView.torchMode = 0;
readerView.device = [self frontFacingCameraIfAvailable];
[readerView start];
[self.view addSubview: readerView];
}
-(void)relocateReaderPopover:(UIInterfaceOrientation)toInterfaceOrientation {
if (toInterfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
readerView.previewTransform = CGAffineTransformMakeRotation(M_PI_2);
} else if (toInterfaceOrientation == UIInterfaceOrientationLandscapeRight) {
readerView.previewTransform = CGAffineTransformMakeRotation(-M_PI_2);
} else if (toInterfaceOrientation== UIInterfaceOrientationPortraitUpsideDown) {
readerView.previewTransform = CGAffineTransformMakeRotation(M_PI);
} else {
readerView.previewTransform = CGAffineTransformIdentity;
}
}
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
if (interfaceOrientation == UIInterfaceOrientationLandscapeLeft) {
return YES;
} else if (interfaceOrientation == UIInterfaceOrientationLandscapeRight) {
return YES;
} else {
return NO;
}
}
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) orient
duration: (NSTimeInterval) duration
{
if (orient == UIInterfaceOrientationLandscapeLeft) {
[readerView willRotateToInterfaceOrientation: orient
duration: duration];
}
if (orient == UIInterfaceOrientationLandscapeRight) {
[readerView willRotateToInterfaceOrientation: orient
duration: duration];
}
}
- (BOOL)shouldAutorotate {
UIInterfaceOrientation orientation = [[UIDevice currentDevice] orientation];
if (orientation == UIInterfaceOrientationLandscapeLeft) {
return YES;
} else if (orientation == UIInterfaceOrientationLandscapeRight) {
return YES;
} else {
return NO;
}
}
-(NSUInteger) supportedInterfaceOrientations
{
return UIInterfaceOrientationMaskLandscape;
}
最佳答案
我遇到了同样的问题并顺利解决了!
我只需要打电话:
[reader willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
在包含 ZbarReaderView 的 View Controller 的 willRotate... 中。
关于objective-c - ZBarReaderView UIView 相机方向问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14087736/