超级简单的问题,我很为难的:iOS的检测将停止
我使用一个UISlider
当用户拖动(但不自来水)的滑块时应该检测。这个工程和拇指显然可以拖动,但我需要在拖动事件停止时得到通知。有没有一个控制事件,我没有看到,这将允许我区分拖动停止和水龙头停止?
或者是否有一些简单的方法在touchesEnded:
方法中完成此操作?
任何帮助表示赞赏。谢谢。
超级简单的问题,我很为难的:iOS的检测将停止
我使用一个UISlider
当用户拖动(但不自来水)的滑块时应该检测。这个工程和拇指显然可以拖动,但我需要在拖动事件停止时得到通知。有没有一个控制事件,我没有看到,这将允许我区分拖动停止和水龙头停止?
或者是否有一些简单的方法在touchesEnded:
方法中完成此操作?
任何帮助表示赞赏。谢谢。
[ratingScale addTarget:self action:@selector(slideEnds:) forControlEvents:UIControlEventTouchDragInside];
其中ratingScale将您的样品UISlider & slideEnds将您的样品选择为上述事件被解雇。
touchDragInside标准可确保只要继续拖动就可以触发选择器。如果您只是在滑块上注册轻击,它不会触发。
使用此:
[slider addTarget:self action:@selector(slidingStopped:)forControlEvents:UIControlEventTouchUpInside];
- (void) slidingStopped:(id)sender
{
NSLog(@"stopped sliding");
}
我知道这是古老的,但这并不完整。您还需要为UIControlEventTouchUpOutside发送消息,否则用户可能会将他们的手指拖动到控件边界之外,然后松开并且您不会收到消息。 – FreaknBigPanda 2013-07-22 14:56:01
@FreaknBigPanda你是对的!我建议编辑。 – tonytony 2013-08-18 19:31:13
我知道这是一个老的文章,但这里就是我所做的。它可以适应UISlider问题。
BOOL buttonDidMove = NO;
- (void)viewDidLoad
{
[super viewDidLoad];
UIButton *button = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[button addTarget:self action:@selector(buttonMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[button addTarget:self action:@selector(buttonTouchUpInside) forControlEvents: UIControlEventTouchUpInside];
[button setTitle:@"Tap Me" forState:UIControlStateNormal];
button.frame = CGRectMake(80.0, 210.0, 160.0, 40.0);
button.backgroundColor = [UIColor yellowColor];
[self.view addSubview:button];
}
- (void)buttonTouchUpInside
{
if (buttonDidMove) {
buttonDidMove = NO;
return;
}
NSLog(@"buttonTouchUpInside");
[self initNetworkCommunication];
}
- (void)buttonMoved:(UIButton *)control withEvent:(UIEvent *)event
{
NSLog(@"buttonMoved");
buttonDidMove = YES;
UITouch *touch = [[event touchesForView:control] anyObject];
control.center = [touch locationInView:self.view];
}
希望这会有所帮助。
我怎么才能检测到用户的手指拖动后,只是触摸? – 2012-04-27 04:15:54