CGAffineTransform旋转并调整滑块值的大小

时间:2013-04-19 09:27:32

标签: ios objective-c rotation uislider cgaffinetransform

我正在使用SliderResizeRotate -

对于旋转 -

 CGAffineTransform transform = editingView.transform;
  transform =  CGAffineTransformMakeRotation(sliderVal * 2*M_PI / 30);
  editingView.transform = transform;

对于Resize-

CGAffineTransform t = CGAffineTransformMakeScale(sliderVal/30, sliderVal/30);
  CGPoint center = editingView.center; 
  [UIView animateWithDuration:0.5
                   animations:^{
                      editingView.transform = t;
                     editingView.center = center;
                   }
                   completion:^(BOOL finished) {

                   }];

使用上面的代码,两者分别正常工作。

但是我必须resize旋转的视图,或者旋转调整大小的视图。

我看到很多建议分别出现,因为我使用CGAffineTransformMakeRotationCGAffineTransformMakeScale,如果我使用CGAffineTransformScaleCGAffineTransformRotation那么我的问题就会解决。

问题是当我使用CGAffineTransform然后缩放不正确时,View会从屏幕上消失。

2 个答案:

答案 0 :(得分:5)

您正在使用editingView.transform行设置视图的转换矩阵。

您应该更改旋转代码:

CGAffineTransform transform = editingView.transform;
transform =  CGAffineTransformMakeRotation(sliderVal * 2*M_PI / 30);
editingView.transform = CGAffineTransformConcat(editingView.transform, transform);

并调整大小:

CGAffineTransform t = CGAffineTransformMakeScale(sliderVal/30, sliderVal/30);
CGPoint center = editingView.center; 
[UIView animateWithDuration:0.5
                   animations:^{
                      editingView.transform = CGAffineTransformConcat(editingView.transform,t);
                      editingView.center = center;
                   }
                   completion:^(BOOL finished) {

                   }];

使用CGAffineTransformConcat,您可以将2个变换矩阵相加,这样您就不会丢失旧的变换。您可以使用CGAffineTransformIdentity重置转换。

答案 1 :(得分:3)

        CGAffineTransform translate = CGAffineTransformMakeTranslation(self.webView.frame.origin.x,self.webView.frame.origin.y - self.webView.frame.size.height * 0.25);
        CGAffineTransform scale = CGAffineTransformMakeScale(0.6, 0.6);
        CGAffineTransform transform =  CGAffineTransformConcat(translate, scale);
        transform = CGAffineTransformRotate(transform, degreesToRadians(-10));

        [UIView beginAnimations:@"MoveAndRotateAnimation" context:nil];
            [UIView setAnimationCurve:UIViewAnimationCurveEaseInOut]; 
            [UIView setAnimationDuration:2.0];

            editingView.transform = transform;

        [UIView commitAnimations];

试试这个......