所以我有一个大的UIButton
,这是一个UIButtonTypeCustom
,并且按钮目标被称为UIControlEventTouchUpInside
。我的问题是如何确定触摸发生在UIButton
的哪个位置。我想要这个信息,所以我可以从触摸位置显示一个弹出窗口。这是我试过的:UIButton TouchUpInside触摸位置
UITouch *theTouch = [touches anyObject];
CGPoint where = [theTouch locationInView:self];
NSLog(@" touch at (%3.2f, %3.2f)", where.x, where.y);
和各种其他迭代。按钮的目标方法通过sender
从它那里得到信息:
UIButton *button = sender;
那么,有没有办法,我可以使用类似:button.touchUpLocation
?
我在网上看,找不到类似这样的事情,所以在此先感谢。
没有touchUpLocation,UIButton的是你不能得到控制UIButton点击的位置。 http://developer.apple.com/library/ios/#DOCUMENTATION/UIKit/Reference/UIButton_Class/UIButton/UIButton.html –
我的意思不是字面上touchUpLocation,我的意思是这样的 – Andrew
@ Praveen-K,这是不正确的。 UIKit支持采取第二个参数的动作,即触发动作的UIEvent。从中你可以得到触摸列表,每个触摸都有一个位置。看到我在下面发布的代码。但是,UIButton确实没有返回最后点击位置的方法。 – Caleb