Objective-C: タッチ系イベントを取得する
Swiftを使おうと思いつつもiOS8でアプリリリースをするとなると結構先になってしまうので、まだまだObjective-Cで書いてた方がいい感じです。
タッチ系Eventの取得は以下になります。スワイプとかただのドラッグとかはもっといい関数がありますが、これだと汎用性高く色々やれると思います。
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view.window]; NSLog(@"touchesBegan:%.0f, %.0f", pt.x, pt.y); } - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view.window]; NSLog(@"touchesMoved:%.0f, %.0f", pt.x, pt.y); } - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view.window]; NSLog(@"touchesEnded:%.0f, %.0f", pt.x, pt.y); } - (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event { CGPoint pt = [[touches anyObject] locationInView:self.view.window]; NSLog(@"touchesCancelled:%.0f, %.0f", pt.x, pt.y); }
詳細! Objective-C iPhoneアプリ開発 入門ノート Xcode5+iOS7対応
- 作者: 大重美幸
- 出版社/メーカー: ソーテック社
- 発売日: 2013/11/02
- メディア: 単行本
- この商品を含むブログ (2件) を見る