iOS:检测包含多个图像的 UIImageView 中的图像触摸

标签 ios objective-c uiimageview touch collision-detection

我得到了一个由两个图像组成的 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/

相关文章:

ios - NSJSON序列化到核心数据

ios - 以编程方式使用高清标签栏图标?

ios - 虚线边框 UIImageView swift

objective-c - 将 png 加载到 UIImageView iOS

ios - 我可以使用 XCode 中的 Settings Bundle 编辑器指定除“Settings”之外的 UI吗?

ios - 将 Flutter 应用上传到 AppStore 导致 App.framework 不支持 Info.plist 中指定的最低 OS 版本

iphone - 如何为充满空气的气球制作动画

ios - 在 iOS 13 的 iPhone 上将纵向 View Controller 推到横向 View Controller 上

IOS 根据 NSMutableArray 值更改 Uitableview 中的 Accessory View Cell Image

ios - Visual Studio Cordova - 无法部署应用程序