我想“检测”旋转 - 而不是跟踪它。我需要按M_PI/8
顺时针或逆时针处理手势旋转,然后按M_PI_2
或-M_PI_2
旋转我的图像。
是否可以使用UIRotationGestureRecognizer
?
答案 0 :(得分:0)
此代码可以根据需要运行:
- (IBAction)rorationDid:(UIRotationGestureRecognizer *)recognizer
{
static CGFloat angle = 0;
if (recognizer.state == UIGestureRecognizerStateBegan)
angle = recognizer.rotation;
if (recognizer.state != UIGestureRecognizerStateEnded)
return;
float rotation = 0;
if (angle - recognizer.rotation > M_PI/8)
rotation = -M_PI_2;
if (angle - recognizer.rotation < -M_PI/8)
rotation = M_PI_2;
if (rotation != 0.0)
{
// Let's do rotation
}
}
更新:
此代码:static CGFloat angle = 0;
应该是@property
而不是static
。