zbar屏幕旋转

转载自:http://www.ikoding.com/ios-zbarreaderview-interface-orientation/

在iPad应用中,如果没有特殊情况,需要让应用支持所有屏幕方向。在iPad中使用ZBar扫描二维码时,需要在屏幕旋转时调整摄像头的方向,而ZBarReaderView并不会在屏幕旋转时自动调整方向,所以需要我们以某种方式进行控制。

如果使用的是ZBarReaderViewController,那么这件事情相对比较简单,使用以下方式进行设置即可支持所有屏幕方向。

ZBarReaderViewController *reader = [[ZBarReaderViewController alloc]init];
reader.supportedOrientationsMask = ZBarOrientationMaskAll;

我在项目中使用的是ZBarReaderView,在网上找的一些方案都不能很好的解决问题,最终用以下方式解决了屏幕旋转问题,并且非常简洁。

ZBarReaderView中摄像头的默认方向为UIInterfaceOrientationPortrait,因此需要在初始化时调用该方法,以保证ZBarReaderView初始化时处于正确的方向。代码如下:

ZBarReaderView *readerView = [[ZBarReaderView alloc]init];
[readerView 
    willRotateToInterfaceOrientation:
        [[UIApplication sharedApplication] statusBarOrientation] 
    duration:
        [[UIApplication sharedApplication]statusBarOrientationAnimationDuration]];

此外,添加以下部分以保证ZBarReaderView可以正确处理屏幕旋转,代码如下:

- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
    return YES;
}

//旋转屏幕
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
    duration:(NSTimeInterval)duration
{
    [readerView willRotateToInterfaceOrientation:toInterfaceOrientation duration:duration];
}



转载自:http://stackoverflow.com/questions/14087736/zbarreaderview-uiview-camera-orientation-issue


评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值