我得到了一个由两个图像组成的 UIImageView,并激活了透明 channel 。
View 看起来像这样: image
我希望能够精确地检测到中心圆内的触摸,并将它们与外圆中的触摸区分开来。
我正在考虑一种基于两个圆之间差异的碰撞检测算法。首先在外层测试,看是否有碰撞,然后在内层测试。如果在内层则激活内层按钮,否则激活外层按钮。
对此有什么帮助或建议吗?
我应该创建一个 github 存储库以便每个人都可以在其中做出贡献吗?
最佳答案
这里有一些东西可以帮助你:
UIImageView *myImageView;
// In viewDidLoad, the place you are created your UIImageView place this:
myImageView.userInteractionEnabled = YES;
UITapGestureRecognizer *tapInView = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(tapInImageView:)];
[myImageView addGestureRecognizer:tapInView];
}
-(void)tapInImageView:(UITapGestureRecognizer *)tap
{
CGPoint tapPoint = [tap locationInView:tap.view];
CGPoint centerView = tap.view.center;
double distanceToCenter = sqrt((tapPoint.x - centerView.x)*(tapPoint.x - centerView.x) + (tapPoint.y - centerView.y)*(tapPoint.y - centerView.y) );
if (distanceToCenter < RADIUS) {
// It's in center
} else {
// Touch outside
}
关于iOS:检测包含多个图像的 UIImageView 中的图像触摸,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27381413/