iphone - "pointInside:"是如何工作的?

标签 iphone objective-c ios uiview

我正在做一些 HitTest ,遇到了一个令人困惑的情况。

我有两个按钮“favoriteButton”和“shareButton”。即使按钮不重叠,以下代码也会导致“a”和“b”为真:

CGPoint dunno = CGPointMake(11, 7);

BOOL a = [self.favoriteButton pointInside:dunno withEvent:nil];
BOOL b = [self.shareButton pointInside:dunno withEvent:nil];

为了证明这一点,这里是调用此代码时两个按钮的描述输出。

Printing description of _favoriteButton:
<UIButton: 0x5da8c90; frame = (10 6; 37 35); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5da8d40>>
Printing description of _shareButton:
<UIButton: 0x5da7150; frame = (46 6; 30 35); opaque = NO; autoresize = RM+BM; layer = <CALayer: 0x5da59b0>>

这是怎么回事?我是否误解了输出应该是什么?

最佳答案

好吧,根据文档@Nippysaurus

http://developer.apple.com/library/iOS/documentation/UIKit/Reference/UIView_Class/UIView/UIView.html#//apple_ref/occ/instm/UIView/pointInside:withEvent :

A point that is in the receiver’s local coordinate system (bounds).

这意味着 CGPoint dunno = CGPointMake(11, 7); 点在 View 内部,因为 View 的边界与同一 View 的框架不同。

关于iphone - "pointInside:"是如何工作的?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/7159538/

相关文章:

ios - 获取用于在 prepareForSegue 中编辑行的索引路径?

ios - 我正在构建一个 iOS 应用程序,只是选择使用 AWS iOS SDK 而不是 BaaS 来构建后端。我刚刚为自己创造了哪些额外的工作?

iphone - 访问方法内部变量时 iPhone (C++) 上的 EXC_BAD_ACCESS

iphone - 根据 Setting.bundle 切换开关状态更改应用程序的 MainView?

iphone - UITableViewCell 亮点和效果

iphone - 应用程序仍在后台运行 Xcode 4.2 iOS 5

iphone - 如何在基于 View /选项卡栏的应用程序中隐藏选项卡栏

iphone - 在 UIScrollView 中覆盖 drawRect 时的黑色背景

ios - 如何在 iOS 中适本地发布多个表单变量

ios - 原因 : '-[CNContact setSnapshot:]: unrecognized selector sent to instance 0x7fc84c8491c0'