2012-05-07 7 views
0

私はデュアルアプリケーションを持っており、touchesBeganのコードブロックをiPhoneコードからiPadにコピーしました。私は何も変更を加えていないし、メソッドは、最初のタッチのために私にxとyのためのゼロを常に与える。iPhone touchesBegianがiPadで動作しない、xとyは常にゼロ

コードブロック:私は常に正しい方法はUITouch取得することを見てきました

-(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

[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にコピーしました。 –

+0

iPadシミュレータ。 – mbm29414

関連する問題