我制作了一个应用程序,用时钟设置 sleep 定时器。基本上它是一个时钟,用户可以用一只手移动它来设置他的 sleep 时间。我试着用<旋转图像strong>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");
}
最佳答案
具体来说,可以自定义一个rotateView,然后:
1:在“touchesBegan”的委托(delegate)方法中,获取手指的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。
如果有什么不明白的,想了解更多细节,你可以回信。
关于ios - 通过触摸旋转图像,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5178022/