Bob*_*300 3 objective-c uiview ios zbar-sdk zbar
我目前正在开发一个使用ZBarSDK读取QR码的iPad应用程序.
我正在使用ZBarReaderView (NOT UIViewController),所以我正在UIView使用绘制的前置摄像头CGRect(参见下面的代码).
我的问题是相机在视图中出现在它的侧面.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;
}
Run Code Online (Sandbox Code Playgroud)
小智 6
我得到了同样的问题,并解决了它!
我只需要打电话:
[reader willRotateToInterfaceOrientation: toInterfaceOrientation duration: duration];
Run Code Online (Sandbox Code Playgroud)
在包含ZbarReaderView的视图控制器的willRotate ...内.
| 归档时间: |
|
| 查看次数: |
4428 次 |
| 最近记录: |