В настоящее время я разрабатываю приложение для iPad, которое использует ZBarSDK для чтения QR-кодов.
Я использую ZBarReaderView
(НЕ 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;
}