2009-07-10 31 views
0

触摸可以指定自己获取触摸位置在自己的坐标系中,但是如何从另一个触摸位置获取触摸位置?说另一个UIview的坐标系?如何获取不同视图的触摸位置?

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event 
{ 
    [UIView beginAnimations:@"box" context:nil]; 
    [UIView setAnimationDuration:1]; 
    [UIView setAnimationBeginsFromCurrentState:YES]; 
    UITouch *touch = [touches anyObject]; 
    box.center = [touch locationInView:self]; 
    [UIView commitAnimations]; 
} 

难道我只是在一个不同的UIview的名称'自我'是?

回答

5

“此方法返回指定视图的坐标系中的UITouch对象的当前位置”,所以我会说是的,您可以在另一个视图中传递。为了确保你可以尝试一个你有两个视图重叠的示例项目,并且NSLog将两个调用的结果记录到两个视图中。

+0

是的,这工作正常。 – 2009-07-10 18:02:01