屏幕上有一串按钮。如果我拖动几个按钮,我如何才能使它触发所有。谢谢你的进阶。
发布于 2014-03-19 10:50:21
尝试过触摸事件吗?
例如:
-(void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
if ([touch.view isKindOfClass:[UIButton class]])
{
if (!buttonArray)
buttonArray = [[NSMutableArray alloc] init];
[buttonArray removeAllObjects];
}
}
-(void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch * touch = [touches anyObject];
if ([touch.view isKindOfClass:[UIButton class]] && ![buttonArray containsObject:touch.view])
{
[buttonArray addObject:touch.view];
}
}
-(void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
for (UIButton * button in buttonArray)
[self buttonEvent:button];
}
-(void)buttonEvent:(UIButton *)but
{
NSLog("buttonEvent :%@", but);
}发布于 2014-03-19 10:46:23
就像你做的那样定义一个常规的动作。然后根据您的要求,在Connections检查器(确保单击IB中的按钮)中使用以下Sent Events之一附加操作:
Touch Drag Enter
Touch Drag Exit
Touch Drag Inside
Touch Drag Outside记住:在UIView和动作之间有很多对多的关系。一个UIView可以附加到多个操作,一个操作可以通过在多个UIView上发送事件来触发。
发布于 2014-03-19 10:54:51
在事件为Touch Up Inside时,添加一个使用Touch Drag Exit的操作,而不是或者可能除了发送事件之外,还可以添加一个事件。当用户将手指拖动到按钮区域外时,该操作将被调用。下面的图像显示了所选“发送”按钮的“连接检查器”和所有可能的发送事件。

https://stackoverflow.com/questions/22503120
复制相似问题