使用ZXingObjC扫描二维码横竖屏对应

/**
 根据屏幕的方向设置扫描的方向
 * @author maguang
 * @param parameter
 * @return result
 */
- (void)showaCapture
{
    CGAffineTransform transform;
    if (self.interfaceOrientation == UIInterfaceOrientationLandscapeLeft)
    {
        self.capture.rotation = 180.0f;
        transform = CGAffineTransformMakeRotation(M_PI/2);
    }
    else if (self.interfaceOrientation == UIInterfaceOrientationLandscapeRight)
    {
        self.capture.rotation = 0.0f;
        transform = CGAffineTransformMakeRotation(-M_PI/2);
    }
    else if (self.interfaceOrientation == UIInterfaceOrientationPortrait)
    {
        self.capture.rotation = 90.0f;
        transform = CGAffineTransformMakeRotation(0);
    }
    else if (self.interfaceOrientation == UIInterfaceOrientationPortraitUpsideDown)
    {
        self.capture.rotation = 270.0f;
        transform = CGAffineTransformMakeRotation(M_PI);
    }
    
    [self.capture setTransform:transform];
    CGRect f = CGRectMake(0, 0, self.view.bounds.size.width, self.view.bounds.size.height);
    self.view.layer.frame=f;
    self.capture.layer.frame = f;
}

1、在 - (void)viewWillAppear:(BOOL)animated

方法中调用上面的方法。

2、同时在响应屏幕旋转的方法中调用这个方法。

posted @ 2014-09-03 08:14  糊涂人  阅读(788)  评论(0编辑  收藏  举报