2016-03-24 10 views
0

私は、Mac上でマウスポインタを動かすのではなく、トラックパッドを使って画面を移動するオブジェクトを必要とするtvOS用のゲームを作成しています。私が持っている問題は、私のゲームで、UIViewControllerがtouchesBeganまたはtouchesMovedを受け取っていないということです。 tvOSに取り組んでいないtouchesBeganについて、ネット上でいくつかのたわ言を読んだ私は、この理論をテストするためにTVOS UIViewControllerがtouchesBeganやtouchesMovedを受け取らない

を小さなプログラムを書いたViewController.h:

#import <UIKit/UIKit.h> 
@interface ViewController : UIViewController { 
    CGPoint cursorLocation; 
    UIImageView* cursorImage; 
} 
@end 

ViewController.m:

#import "ViewController.h" 

@interface ViewController() 

@end 

@implementation ViewController 

- (void)viewDidLoad { 
    [super viewDidLoad]; 
    // Do any additional setup after loading the view, typically from a nib. 
    cursorImage = [[UIImageView alloc] initWithFrame:CGRectMake(0.0, 0.0, 92.0, 92.0)]; 
    cursorImage.center = CGPointMake(CGRectGetMidX([UIScreen mainScreen].bounds), CGRectGetMidY([UIScreen mainScreen].bounds)); 
    cursorImage.image = [UIImage imageNamed:@"Cursor"]; 

    cursorImage.backgroundColor = [UIColor clearColor]; 
    cursorImage.hidden = NO; 
    [self.view addSubview:cursorImage]; 

} 

- (void)didReceiveMemoryWarning { 
    [super didReceiveMemoryWarning]; 
    // Dispose of any resources that can be recreated. 
} 

- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 
    cursorLocation = CGPointMake(-1, -1); 
} 

- (void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event { 
    UITouch* touch = [touches anyObject]; 
    CGPoint location = [touch locationInView:self.view]; 
    if ((cursorLocation.x == -1) && (cursorLocation.y == -1)) { 
     cursorLocation = [touch locationInView:self.view]; 
    } else { 
     float xDiff = location.x - cursorLocation.x; 
     float yDiff = location.y - cursorLocation.y; 
     CGRect rect = cursorImage.frame; 
     if ((rect.origin.x + xDiff >=0) && (rect.origin.x + xDiff <= self.view.frame.size.width)) { 
      rect.origin.x += xDiff; 
     } 
     if ((rect.origin.y + yDiff >=0) && (rect.origin.y + yDiff <= self.view.frame.size.height)) { 
      rect.origin.y += yDiff; 
      cursorImage.frame = rect; 
      cursorLocation = location; 
     } 
    } 
} 

@end 

私のテスト美しく働いた!私の質問は、touchesBeganまたはtouchesMovedが私のフル・アプリケーションのViewControllerによって受信されないようにすることができるものです(この質問のソースは長すぎます)。 Spitball away - 私はアイデアがなくなり、あなたが持っている可能性のある提案を歓迎する!

+0

この[こちら](https://developer.apple.com/library/tvos/documentation/General/Conceptual/AppleTV_PG/DetectingButtonPressesandGestures.html#//apple_ref/doc/)のtvOSドキュメントを読むことから始めてみることをお勧めします。 uid/TP40015241-CH16-SW1)。私はあなたがおそらくプレスが必要だと思う.Began ... またこれはかなり[既にここにある] [http://stackoverflow.com/questions/32516535/how-can-i-receive-touches-using-tvos ) – earthtrip

+0

ご覧のとおり、touchesBeganはうまく動作します(テストコードで示されているように)。だから問題は、それは完全なアプリで動作しないのですか?そして、プレスBeganが正しければ、なぜプレスがないのですか?Movedも同様ですか? – headbanger

+0

レコードの場合、pressBeganはView Controllerにも渡されていません。奇妙な。 – headbanger

答えて

1

サンプルコードにはジェスチャ認識機能はありませんが、あなたの完全なアプリはおそらくそうです。応答によってはtouchesBegan:がレスポンダチェーンに送信されないことがあります。

完全なアプリケーションを再試行する必要がありますが、できるだけ多くのジェスチャ認識ツールが削除されているため、touchesBegan:メソッドが呼び出されることがあります。

あなたは問題が実際にジェスチャーであると判断した場合、その後、あなたは問題のジェスチャーにNOからcancelsTouchesInViewを設定することにより、レスポンダチェーンの方法と協力するジェスチャーを取得、またはNOdelaysTouchesBeganを設定することで可能(つまり、必要がありますがすでにデフォルトになっています)。

+0

これは素晴らしい提案です。しかし、私はすでに試したことがあります。それを修正しませんでした。現時点では、ビューがレスポンダーチェーンをブロックしている可能性があります。 – headbanger

関連する問題