我目前正在开发一款使用ZBarSDK读取QR码的iPad应用程序。ZBarReaderView UIView相机方向问题
我使用ZBarReaderView
(NOT UIViewController
),所以我示出被使用CGRect
取用一个UIView
置摄像头的前部(参见下面的代码)。
我的问题是相机在视图内出现在它的一侧。 iPad应用程序只能开发为在横向模式下工作。
当UIView
现在出现时,图像是在它的一边,我不知道如何解决它。我尝试使用CGAffineTransform
,它成功地改变了角度,但如果iPad以另一种方式翻转,这将如何处理?
我看到一些关于这个类似问题的其他文章,但没有解决方案已经为我工作。值得注意的是我使用的IOS6,请记住我使用ZBarReaderView
,所以supportedOrientationsMask
不可用。
我希望用户能够以直立的姿势看到相机视图,而不管风景是向左还是向右。不过现在,无论它转向哪个方向,视频都是横向的(所以我可以看到自己与侧面成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;
}
非常感谢你回答这个问题,但是我可以知道什么是readerView.device?如何实现相机翻转,让用户选择是否要使用前置或后置摄像头? –