【问题标题】:Cocoa Touch - UIButtons - Subclassing UIButtonCocoa Touch - UIButtons - 子类化 UIButton
【发布时间】:2010-09-24 23:03:18
【问题描述】:

大家好,谁能解释我如何继承 UIButton 并覆盖一些方法,以便当用户拖出按钮时它会立即出现?问题是当我拖出按钮框架时,它仍然处于活动状态并向下移动。我希望它在手指离开按钮框架后立即停止。有什么想法吗?

(可可触摸)

【问题讨论】:

    标签: xcode uibutton subclass drag


    【解决方案1】:

    如果有人遇到过这个问题,下面的代码可以在拖动时实现极其准确的边缘感应。如果你拖出按钮,它不会像往常一样超出按钮的边缘。

    (我继承了 UIButton 并做了以下:)

    - (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
        touchBlocker = TRUE;
        self.highlighted = TRUE;
        NSLog(@"Touch Began");
    }
    - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
        UITouch *touch = [[event allTouches] anyObject];
        CGPoint location = [touch locationInView:self];
        if (touchBlocker) {
            if (!CGRectContainsPoint([self bounds], location)) {
                touchBlocker =FALSE;
                self.highlighted = FALSE;
                NSLog(@"Touch Exit");
            }   
        } else if (CGRectContainsPoint([self bounds], location)) {
            touchBlocker = TRUE;
            self.highlighted = TRUE;
            NSLog(@"Touch Enter");
        }
    
    }
    - (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {
        touchBlocker = FALSE;
        self.highlighted = FALSE;
        NSLog(@"Touch Ended");
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2013-01-09
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多