2012-05-07 37 views
0

我有一個雙重應用程序,並將touchesBegan的代碼塊從iPhone代碼複製到iPad。我沒有做任何改變,並且該方法總是給我一個零和x和y的第一次觸摸。iPhone touchesBegian不在iPad上工作,x和y總是爲零

的代碼塊:

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { 

    int iCardId; 

    NSSet *allTouches = [event allTouches]; 

    // we are dealing with one finger get first touch 

    // get first touch 
    UITouch *touch=[[allTouches allObjects] objectAtIndex:0]; 

    // get the x and y 
    CGPoint pt = [touch locationInView: self.view]; 
    float x=pt.x; // this is always a zero 
    float y=pt.y; // this is always a zero 
    ......... 
    ......... 
    ......... 
} 

回答

0

我始終認爲,正確的方式來獲得UITouch[touches anyObject]。試試看看你是否仍然得到(0,0)

編輯/更新

我成立了一個新的單一視圖的應用程序,放在下面的代碼到UIViewController

-(void) touchesBegan: (NSSet *) touches withEvent: (UIEvent *) event { 
    NSSet *allTouches = [event allTouches]; 
    // we are dealing with one finger get first touch 
    // get first touch 
    UITouch *touch=[[allTouches allObjects] objectAtIndex:0]; 
    // get the x and y 
    CGPoint pt = [touch locationInView:[self view]]; 
    NSLog(@"(%f,%f)", pt.x, pt.y); 
} 

這似乎給我適當的座標。你把你的代碼放在哪裏?

+0

嗨,是iPad嗎?該代碼適用於iPhone,並將其複製到iPad,其中它不起作用,iPad模擬器 –

+0

。 – mbm29414

相關問題