防止旋转的CGAffineTransform被视图自动旋转破坏

时间:2012-08-08 09:18:43

标签: iphone ios ipad ios5

我有一个UIImageView的子类,其中包含一些手势识别器,我用它来将变换应用到自身。我对平移或缩放没有任何问题,但旋转的变换在设备本身旋转时会引起问题。基本上每次旋转设备都会产生缩放图像的效果......

我认为一切旋转都可能导致旋转变换出现问题,但是有没有人知道这种行为的方法呢?最好能在UIImageView子类中实现的东西?我需要其他兄弟视图来自动调整大小,所以我无法在父视图中禁用“自动调整大小视图”。

以下是负责创建旋转变换的代码,如果它有帮助:

- (void)setUpRotation
{
    UIRotationGestureRecognizer *newRecognizer = [[UIRotationGestureRecognizer alloc] initWithTarget:self action:@selector(handleRotationGesture)];
    newRecognizer.delegate = self;
    self.rotationRecognizer = newRecognizer;
    [self addGestureRecognizer:self.rotationRecognizer];
    [newRecognizer release];
    self.userInteractionEnabled = YES;
}

- (void)handleRotationGesture
{
    // Initial state
    if(self.rotationRecognizer.state == UIGestureRecognizerStateEnded)
    {        
        lastRotation = 0.0;
        return;
    }

    CGFloat rotation = 0.0 - (lastRotation - self.rotationRecognizer.rotation);    
    CGAffineTransform currentTransform = self.transform;
    self.transform  = CGAffineTransformRotate(currentTransform,rotation);  

    lastRotation = self.rotationRecognizer.rotation; 
}

这是iOS 5.0 btw。

0 个答案:

没有答案
相关问题