尝试编写一个简单的应用程序,以允许用户拖动图像

时间:2012-10-31 18:06:02

标签: iphone

我正在尝试编写一个应用程序,允许一个人拖动地球的图像。

当用户开始拖动他的脚时会调用方法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;          
    }
}

1 个答案:

答案 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;          
    }
}