QRCode在与位置

时间:2017-08-09 05:06:31

标签: ios objective-c iphone landscape image-rotation

我正在开发一个应用程序,我在全图像视图上有QRCode图像,我使用Pinch Gesture在全图像视图上设置了QRCode图像,我使用的代码是:

-(void)gestureForEmojis
{
    self.FullImageView.userInteractionEnabled = YES;
    imageview.userInteractionEnabled = YES;

    UIPanGestureRecognizer *moveImageGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveEmojis:)];
    [moveImageGesture setMinimumNumberOfTouches:1];
    [moveImageGesture setMaximumNumberOfTouches:1];
    [imageview addGestureRecognizer:moveImageGesture];

    pinchGestRecognizerForEmojis = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(scaleEmojis:)];
    pinchGestRecognizerForEmojis.delegate = self;
    [imageview addGestureRecognizer:pinchGestRecognizerForEmojis];

}
- (void)scaleEmojis:(UIPinchGestureRecognizer *)pinchGestRecognizer1
{
    _myScrollView.scrollEnabled=NO;
    imageview.transform = CGAffineTransformScale(imageview.transform, pinchGestRecognizer1.scale, pinchGestRecognizer1.scale);

    pinchGestRecognizer1.scale = 1;
}
- (void)moveEmojis:(UIPanGestureRecognizer *)recognizer
{

    _myScrollView.scrollEnabled=NO;

    CGPoint movement;

    if(recognizer.state == UIGestureRecognizerStateBegan || recognizer.state == UIGestureRecognizerStateChanged)
    {
        CGRect rec = recognizer.view.frame;
        CGRect imgvw = self.FullImageView.frame;

        if((rec.origin.x >= imgvw.origin.x && (rec.origin.x + rec.size.width <= imgvw.origin.x + imgvw.size.width)))
        {
            CGPoint translation = [recognizer translationInView:recognizer.view.superview];
            movement = translation;
            recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
            rec = recognizer.view.frame;

            if( rec.origin.x < imgvw.origin.x )
                rec.origin.x = imgvw.origin.x;

            if( rec.origin.x + rec.size.width > imgvw.origin.x + imgvw.size.width )
                rec.origin.x = imgvw.origin.x + imgvw.size.width - rec.size.width;

            if( rec.origin.y < imgvw.origin.y )
                rec.origin.y = imgvw.origin.y;

            if( rec.origin.y + rec.size.height > imgvw.origin.y + imgvw.size.height )
                rec.origin.y = imgvw.origin.y + imgvw.size.height - rec.size.height;


            recognizer.view.frame = rec;

            [recognizer setTranslation:CGPointZero inView:recognizer.view.superview];

       }
    }
    else if (recognizer.state == UIGestureRecognizerStateEnded)
    {
        CGRect rec = recognizer.view.frame;
        CGRect imgvw = self.FullImageView.frame;

        if((rec.origin.x >= imgvw.origin.x && (rec.origin.x + rec.size.width <= imgvw.origin.x + imgvw.size.width)))
        {
            CGPoint translation = [recognizer translationInView:recognizer.view.superview];
            movement = translation;
            recognizer.view.center = CGPointMake(recognizer.view.center.x + translation.x, recognizer.view.center.y + translation.y);
            rec = recognizer.view.frame;

            if( rec.origin.x < imgvw.origin.x )
                rec.origin.x = imgvw.origin.x;

            if( rec.origin.x + rec.size.width > imgvw.origin.x + imgvw.size.width )
                rec.origin.x = imgvw.origin.x + imgvw.size.width - rec.size.width;

            if( rec.origin.y < imgvw.origin.y )
                rec.origin.y = imgvw.origin.y;

            if( rec.origin.y + rec.size.height > imgvw.origin.y + imgvw.size.height )
                rec.origin.y = imgvw.origin.y + imgvw.size.height - rec.size.height;


            recognizer.view.frame = rec;

            [recognizer setTranslation:CGPointZero inView:recognizer.view.superview];
        }

        NSLog(@"%@", NSStringFromCGRect(recognizer.view.frame));

        yourArray = [NSMutableArray new];

        [yourArray addObject:[NSString stringWithFormat:@"%f",recognizer.view.frame.origin.x]];
        [yourArray addObject:[NSString stringWithFormat:@"%f",recognizer.view.frame.origin.y]];
        [yourArray addObject:[NSString stringWithFormat:@"%f",recognizer.view.frame.size.width]];
        [yourArray addObject:[NSString stringWithFormat:@"%f",recognizer.view.frame.size.height]];

        [NSKeyedArchiver archiveRootObject:yourArray toFile:yourArrayFileName];
    }
}

现在当我在一个位置上设置QRCode然后我已经将该位置保存在数组中时,我的问题是当设备旋转到横向时,QRCode的位置会显示在其他位置。我只是在旋转时转换完整的图像视图而不是整个View控制器,我必须根据设备在完整图像视图上的旋转在相同的保存位置上显示QrCode。我在旋转显示QRCode时使用的代码:

x =[[retreivedQRLocation objectAtIndex:0]floatValue];
                    y =[[retreivedQRLocation objectAtIndex:1]floatValue];
 imageview = [[UIImageView alloc]
                             initWithFrame:CGRectMake(x, y, width, height)];
                [imageview setContentMode:UIViewContentModeScaleAspectFit];
                imageview.backgroundColor = [UIColor clearColor];
                imageview.image = self.getsImage;
                imageview.userInteractionEnabled = YES;
                if ( [self.typeofphone isEqualToString:@"normal"])
                {
                    [self.FullImageView addSubview:imageview];
                }

如果有人有任何建议,请告诉我。非常感谢。感谢。

0 个答案:

没有答案