[SDK]iPhoneアプリ開発初心者質問箱34[touch][iPad]
■ このスレッドは過去ログ倉庫に格納されています
0453名称未設定
2013/09/20(金) 10:25:35.40ID:JeasXaKx0半径だけで判定の場合
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint p = [[touches anyObject] locationInView:self];
CGFloat w = self.bounds.size.width;
CGFloat h = self.bounds.size.height;
CGFloat targetRadius = w * 0.7 * 0.5;
CGPoint targetCenter = CGPointMake(w/2, h/2);
//pとtargetCenterの距離がtargetRadius以下ならHit!!
CGFloat r = sqrt(pow(p.x - targetCenter.x, 2.0) + pow(p.y - targetCenter.y, 2.0));
if (r <= targetRadius) { NSLog(@"Hit!!"); }
}
■ このスレッドは過去ログ倉庫に格納されています