1

我制作了一个应用程序,它用时钟设置睡眠定时器。基本上它是一个时钟,它有一只手,用户可以移动它来设置他的睡眠时间。我试图用uitouch旋转图像,但它从中间旋转,但我想要它从尖端旋转。其次,我希望图像仅在用户触摸图像的尖端时旋转,但在我的项目中,当使用触摸屏幕的任何部分时,图像也会旋转。我也想在两个方向上旋转图像但在我的项目中,由于这种方法,它只能顺时针移动

image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

任何人都可以给我关于如何完成的提示或解决方案吗?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
    //

        touch = [[event allTouches] anyObject];
        touchLocation = [touch locationInView:touch.view];

        NSLog(@"began");

    }


    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        // get touch event

        [image.layer setAnchorPoint:CGPointMake(0.0,0.0)];



        if ([touch view] == image) {
            image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

        //image.center = touchLocation;
    }

      }

    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
        NSLog(@"end");



    }
4

3 回答 3

2

详细来说,你可以自定义一个rotateView,然后:

1:在“touchesBegan”的委托方法中,获取finger的initialPoint和initialAngle。

2:在“touchesMoved”期间,获取新的手指点:

CGPoint newPoint = [[touches anyObject] locationInView:self];
[self pushTouchPoint:thePoint date:[NSDate date]];
double angleDif = [self angleForPoint:newPoint] - [self angleForPoint:initialPoint];
self.angle = initialAngle + angleDif;
[[imageView layer] setTransform:CATransform3DMakeRotation(angle, 0, 0, 1)];

3:最后,在“touchesEnded”中你可以计算最终的AngularVelocity。

如果有任何困惑,有关更多详细信息,您可以回信。

于 2012-10-08T04:10:28.767 回答
0

要以其他方式旋转它,您只需使用:

image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));

并且要从提示中旋转,您应该使用 setAnchorPoint(就像您在代码中使用的那样,但我认为您应该这样做:[image setAnchorPoint])。

有关该主题的更多信息:UIImage 的 setAnchorPoint?

于 2011-03-03T14:58:06.067 回答
0

我试图用 uitouch 旋转图像,但它从中间旋转,但我希望它从尖端旋转

我不知道 SDK 中有什么方法可以在其最末端旋转元素。如果您想获得这种效果,请获取长度为两倍且一半透明的时钟句柄图像。这不是直接的解决方案,而是一种解决方法。

我也想在两个方向上旋转图像,但在我的项目中,由于这种方法,它只能顺时针移动

根据 iOS 开发人员文档,正角度值指定逆时针旋转,负值指定顺时针旋转。

于 2011-03-03T08:55:10.710 回答