拖动进入时突出显示按钮

发布于 2024-12-12 18:03:41 字数 124 浏览 0 评论 0原文

刚刚开始探索iOS SDK。我有一些按钮,需要突出显示它们,触摸一次然后拖动。据我了解,当您单击按钮然后拖动到外部然后再次拖动到内部时,会触发 TouchDragEnter 事件。当您单击按钮外部然后拖动到内部时,是否会触发任何事件?

just started to explore iOS SDK. I have some buttons, need to highlight them touching outside once and then drag. As I understand, TouchDragEnter event fires when you click the button then drag outside then drag inside again. Is there any event fires when you click outside the button and then drag inside?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

∞梦里开花 2024-12-19 18:03:42

亚历山大,

搜索相同的信息,我发现您的问题尚未得到解答。您可能已经明白了,但我是这样做的。

请注意,pointInside:withEvent: 方法检查该点是否位于按钮的边界内。由于触摸事件来自视图,因此您必须将其转换为按钮的坐标系。

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
    CGPoint touchPoint = [t locationInView:self.view];

    CGPoint testPoint = [self.view convertPoint:touchPoint toView:aButton];
    if ([aButton pointInside:testPoint withEvent:event]) {
        //Do something
    }
    //rest of code

Alexander,

Searching for the same info, I saw your question hadn't been answered. You've probably already figured it out, but here's how I've done it.

Note that the pointInside:withEvent: method checks to see if the point lies within the button's bounds. Since the touch event is coming from the view, you have to convert it to the button's coordinate system.

-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
for (UITouch *t in touches) {
    CGPoint touchPoint = [t locationInView:self.view];

    CGPoint testPoint = [self.view convertPoint:touchPoint toView:aButton];
    if ([aButton pointInside:testPoint withEvent:event]) {
        //Do something
    }
    //rest of code
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文