通过触摸旋转图像
我制作了一个用时钟设置睡眠计时器的应用程序。基本上,它是一个有单手的时钟,用户可以移动它来设置他的睡眠时间。我尝试使用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");
}
I making an app which sets the sleep timer with a clock .Basically it is clock which has a single hand which user can move to set his sleep time .I tried to rotate the image with uitouch but it rotates from middle but i want it to rotate from the tip.Secondly i want that the image only rotates when user is touching the tip of the image but in my project the image is also rotating when use touches any part of the screen.Also i want to rotate the image in both directions but in my project it moves only clockwise due to this method
image.transform = CGAffineTransformRotate(image.transform, degreesToRadians(1));
Can anybody give me hints or solutions about how can it be done?
- (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");
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
具体来说,可以自定义一个rotateView,然后:
1:在“touchesBegan”的委托方法中,获取手指的initialPoint和initialAngle。
2:在“touchesMoved”中,获取新的手指点:
3:最后,在“touchesEnded”中可以计算最终的AngularVelocity。
如果有任何困惑,为了了解更多详细信息,您可以写信回来。
In detail, you can custom a rotateView,then:
1: In the delegate method of "touchesBegan", get initialPoint of finger and initialAngle.
2: During "touchesMoved",get the newPoint of finger:
3: At last, in "touchesEnded" you can calculate final AngularVelocity.
If anything being confused, for more detail, you can write back.
要以其他方式旋转它,您只需使用:
要从尖端旋转,您应该使用 setAnchorPoint (就像您在代码中使用的那样,但我认为您应该这样做:[image setAnchorPoint])。
有关该主题的更多信息: setAnchorPoint for UIImage?
To rotate it the other way you just use:
And to rotate form the tip you should use setAnchorPoint (like you used in your code, but i think you should do: [image setAnchorPoint]).
more on the subject: setAnchorPoint for UIImage?
我不知道 SDK 中有什么方法可以在其最末端旋转元素。如果您想获得这种效果,请使用时钟手柄图像,您的长度是两倍,其中一半是透明的。这不是一个直接的解决方案,而是一种解决方法。
根据 iOS 开发人员文档,正角度值指定逆时针旋转,负值指定顺时针旋转。
I dont know any way in SDK to rotate an element on its extreme end. If you want to have that effect take the clock handle image you have twice in length with half portion transparent. It is not a direct solution, but a workaround.
As per iOS developer documentation, a positive angle value specifies counterclockwise rotation and a negative value specifies clockwise rotation.