【问题标题】:Is there a way to get the location of a users touch while pressing UIButton?有没有办法在按下 UIButton 时获取用户触摸的位置?
【发布时间】:2012-08-08 08:35:50
【问题描述】:

当我的用户在按住 UIButton 的同时拖动手指时,我可以在该点获取手指的触摸位置吗?如果我不能这样做,我似乎可以创建一个 UIImageView 并赋予它按钮质量。在此之后,我将实现触摸开始、移动和结束的方法。

这些方法;但是,不要在触摸 UIButton 时运行。

我需要这个的原因是因为我想找出触摸拖动外部运动的方向,以及其他各种原因,但如果这不可能,我认为我将不得不创建 UIImageViews。

另外,我没有继承 UIButton,我太初学者了,无法处理苹果集群。

【问题讨论】:

  • 您可能只想为此添加一个手势识别器。

标签: iphone ios uiimageview uibutton


【解决方案1】:

你应该遵循这个:

[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragInside];
[myButton addTarget:self action:@selector(dragHandler:withEvent:) forControlEvents:UIControlEventTouchDragOutside];

-(void)dragHandler:(UIButton *)sender withEvent:(UIEvent *)event
{
    UITouch *touch = [[event allTouches] anyObject];

    NSLog(@"touchInfo:%@", NSStringFromCGPoint([touch locationInView:self.view]);
}

【讨论】:

  • 希望我能给你点赞,但只有 1 个代表
猜你喜欢
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
  • 2019-03-05
  • 1970-01-01
  • 2021-12-07
  • 1970-01-01
  • 1970-01-01
  • 1970-01-01
相关资源
最近更新 更多