我正在尝试编写一个应用程序,允许一个人拖动地球的图像。
当用户开始拖动他的脚时会调用方法touchesmoved
,但[[ event allTouches] anyObject]
永远不会返回earth
对象,因此它永远不会被拖动,
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
UITouch *touch=[[ event allTouches] anyObject];
if ( [touch view] == earth )
{
CGPoint location = [ touch locationInView: self.view];
earth.center=location;
}
}
答案 0 :(得分:0)
触摸使用UITouch *touch=[touches anyObject];
将touchesMoved:
更改为:
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch=[ touches anyObject];
if ( [touch view] == earth )
{
CGPoint location = [ touch locationInView: self.view];
earth.center=location;
}
}