1. 程式人生 > >Object-C中獲取當前觸控點的座標位置

Object-C中獲取當前觸控點的座標位置

//當有一個或多個手指觸控事件在當前檢視或window窗體中響應
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    NSSet *allTouches = [event allTouches];    //返回與當前接收者有關的所有的觸控物件
    UITouch *touch = [allTouches anyObject];   //檢視中的所有物件
    CGPoint point = [touch locationInView:[touch view]]; //返回觸控點在檢視中的當前座標
    int x = point.x;
    int y = point.y;
    NSLog(@"touch (x, y) is (%d, %d)", x, y);
}