我正在制作一个简单的拨盘,在您将手指拖过它时旋转。它旋转得很好,但是当我触摸屏幕上的任何地方并拖动我的手指时它也会旋转。基于触摸问题的旋转
我如何限制第一次接触只在我的imageview对象内?或我哪里错了?
这是我的故障码:
- (id)initWithFrame:(CGRect)frame {
self = [super initWithFrame:frame];
if (self) {
UIImage *image1 = [UIImage imageNamed:@"[email protected]"];
wheelfrom = [[UIImageView alloc] initWithImage:image1];
wheelfrom.frame =CGRectMake(10, -130, 300, 300);
[self addSubview:wheelfrom];
}
return self;
}
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch =[[[event allTouches] allObjects] lastObject];
firstLoc = [touch locationInView:self];
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch =[[[event allTouches] allObjects] lastObject];
CGPoint curLoc = [touch locationInView:self];
float fromAngle = atan2(firstLoc.y-wheelfrom.center.y,
firstLoc.x-wheelfrom.center.x);
float toAngle = atan2(curLoc.y-wheelfrom.center.y,
curLoc.x-wheelfrom.center.x);
float newAngle = angle + (toAngle - fromAngle);
CGAffineTransform cgaRotate = CGAffineTransformMakeRotation(newAngle);
wheelfrom.transform = cgaRotate;
angle = newAngle;
}
感谢您的帮助!
你们很棒。非常感谢,我一直在绞尽脑汁对这个问题进行讨论。这是完美的,我真的很感激它! – 2011-03-10 08:21:17
还有一个额外的问题,图像是一个cirle,但是当我选择它时,它将它当作对象的方块来对待。是否有可能让.png的透明部分不可选?或者如何工作?再次感谢。 – 2011-03-10 08:28:28
ü可以使面积除圆为零(透明)NA .. – 2011-03-10 08:33:33