我有一个问题,关于我应该如何使用基于触摸的事件来旋转UIView。
很简单,我想围绕一个锚点旋转一个UIView,这取决于我在该视图中的触点和关闭位置。想象一下高保真音响上的音量旋钮,你可以用一根手指转动它。
我已经使用CAKeyframeAnimation构建了一个旋转方法,它执行了一个转换.rotation.z,但是我不确定的是(a)我是否应该将它与触摸方法结合使用,以及(b)我如何才能获得触摸相对于底层UIView的坐标/角度,并随后将其指向触摸。
我希望我说的有道理,…有没有人能提点建议?
发布于 2012-11-29 15:55:45
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint newLocationPoint = [[touches anyObject] locationInView:self.superview];
int x = self.superview.center.x;
int y = self.superview.center.y;
float dx = newLocationPoint.x - x;
float dy = newLocationPoint.y - y;
double angle = atan2(-dx,dy);
self.layer.position = self.superview.center;
self.layer.transform = CATransform3DMakeRotation(angle, 0, 0, 1);
NSLog(@"%f,%f ", dx,dy);}
把这个放到你的UIView子类中,瞧!
发布于 2010-11-02 21:54:02
- (void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
CGPoint Location = [[touches anyObject] locationInView:self];
int x = ImageView.center.x;
int y = ImageView.center.y;
float dx = Location.x - x;
float dy = Location.y - y;
double a = atan2(-dx,dy);
ImageView.layer.position = diagramImageView.center;
ImageView.layer.transform = CATransform3DMakeRotation(a, 0, 0, 1);
}https://stackoverflow.com/questions/3754149
复制相似问题