在 Objective c/cocoa touch 中查找接触点
我在找到接触点时遇到问题。
我有一个函数 loadView()
,其中设置了 16 个图块(16 UIImageView
)。
然后在函数中:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// Retrieve the touch point
UITouch *touch=[[event allTouches]anyObject];
CGPoint point= [touch locationInView:touch.view];
CGRect frame = [self frame]; // Error this Line
}
我使用框架来识别使用框架原点按下哪个框架/图块。
但这句话:
CGRect frame = [self frame];
让我发疯。请有人告诉我该怎么做。(解释以及为什么不起作用)。请。
I have a problem to find the touch point.
I have a function loadView()
where I set 16 tiles(16 UIImageView
).
Then In function:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event
{
// Retrieve the touch point
UITouch *touch=[[event allTouches]anyObject];
CGPoint point= [touch locationInView:touch.view];
CGRect frame = [self frame]; // Error this Line
}
I have Used frame to identify which frame/tiles is pressed using frame-origin.
But this line:
CGRect frame = [self frame];
makes me crazy. Plz someone tell me What to do.(with explanation and why not working). Plz.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
使用这个:
Use this :
看起来您正在尝试在 UIViewController 子类中的方法中执行此操作。该行可能应该是:
It seems like you're trying to do this in a method in a UIViewController subclass. The line should probably be:
我仍然有点不清楚你想要什么,但让我们看看这是否对你有帮助。
如果您要移动不同的对象,那么为什么不创建另一个类并使用 UIView 继承它并在子类中定义触摸功能。
示例标题
示例类实现
,或者如果您只需要 UIViewController 中的触摸点。
I am still a bit unclear on what you want, but let's see if this helps you out.
If you are moving different objects then why don't you create another class and inherit it with UIView and define the touch functions in the child class.
Example Header
Example class implementation
or else if you just want the touch points in a UIViewController.