如何确定UIView的旋转角度值是否垂直于Y轴,或者如何将旋转角度限制为仅为圆的四分之一而不是整个360度旋转。我有一个带有以下应用程序CATransformation的UIView。
t = CATransform3DIdentity;
//Add the perspective!!!
t.m34 = 1.0/ 300;
t = CATransform3DRotate(t, 45.0f * M_PI / 180.0f, 0, 1, 0);
self.containerView.layer.sublayerTransform = t;就像在这个link1中一样,并使用以下代码在旋转后的UIView之外的空间中基于UIPanGesture更改旋转角度
- (void)handleRevealGestureStateChangedWithRecognizer:(UIPanGestureRecognizer *)recognizer{
//Calculating percent of translation.
CGPoint translation = [recognizer translationInView:recognizer.view.superview];
CGFloat rotationpercent = translation.x / recognizer.view.frame.size.width;
[self rotate:rotationpercent]; //calling method to transform based on translation value}
- (void)rotate:(CGFloat)rotateDegress{
CGFloat angle = M_PI * rotateDegress;
t = CATransform3DRotate(t, angle, 0, 1, 0);
self.containerView.layer.sublayerTransform = t;}
这会旋转视图,对于某些角度,视图要么垂直于Y轴,要么超出窗口,完全旋转360度,如此link2所示。
因此,可以确定角度是否超过90度,从而禁用旋转。
谢谢
发布于 2014-04-21 19:58:36
您的代码使用以度为单位的角度,这很好(因为您在应用旋转之前转换为弧度)。
只需在手势识别器中添加代码,将角度限制在0到~85度的范围内。(尝试使用上限,看看在页面太薄而无法保持深度错觉之前,您可以获得多接近90%的效果。)问题解决了。
https://stackoverflow.com/questions/23196515
复制相似问题