我正在使用Slider
到Resize
和Rotate
-
对于旋转 -
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
旋转的视图,或者旋转调整大小的视图。
我看到很多建议分别出现,因为我使用CGAffineTransformMakeRotation
,CGAffineTransformMakeScale
,如果我使用CGAffineTransformScale
,CGAffineTransformRotation
那么我的问题就会解决。
问题是当我使用CGAffineTransform
然后缩放不正确时,View
会从屏幕上消失。
答案 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];
试试这个......