如何获得按钮和ID的ID实施touchesMoved同时?

时间:2011-10-26 14:21:41

标签: iphone uibutton

我有一个情况我有一个UIButton类,其中选择一个按钮我得到基于它的按钮的id我正在改变按钮的颜色使用[self addTarget:self action:@selector(buttonPressed :) forControlEvents:UIControlEventTouchUpInside];

通过使用touchesBegan,touchesMoved,touchesEnded方法,我可以将按钮对象拖放到屏幕的任何部分。

现在问题是如果我使用touchesBegan,touchesMoved,touchesEnded方法然后我没有得到按钮的id,所以我无法改变颜色。

那么我怎样才能解决问题?

2 个答案:

答案 0 :(得分:1)

touchesBegan的一个参数是一组UITouch对象。 UITouch具有属性“视图”,这是您点击的视图。像

这样的东西
-(void)touchesBegan:touches withEvent:e
{
    id* myButton = [touches anyObject].view;
}

答案 1 :(得分:0)

如果你在touchesBegan的父视图(包含所有按钮)上调用以下方法:它应该返回你正在触摸的按钮....

- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event

希望这有帮助。

相关问题