【问题标题】:Using touchesBegan & touchesEnded as Swipe使用 touchesBegan 和 touchesEnded 作为 Swipe
【发布时间】:2013-03-15 23:11:17
【问题描述】:

我正在尝试查看用户是否从一个视图、标签等一直滑动到另一个。

这是我的相关代码

ViewController.h:

@property (strong, nonatomic) IBOutlet UITextField *textField;
@property (strong, nonatomic) IBOutlet UILabel *swipeBegin;
@property (strong, nonatomic) IBOutlet UILabel *swipeEnd;

TextField : 显示整个事情是否成功。
SwipeBegin :滑动开始的标签。
SwipeEnd : 滑动应该结束的标签。

ViewController.m :

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch view] == swipeBegin) {
    gestureStartPointTouched = YES;
}

如果滑动开始于“swipeBegin”,则布尔值设置为 YES。

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
UITouch *touch = [touches anyObject];
if ([touch view] == swipeEnd) {        
    if (gestureStartPointTouched == YES) {
        [TextField setText:@"Success"];
    }
}

如果我开始在“swipeBegin”处滑动,则调用 touchesBegan 方法 -> 工作正常

麻烦的部分是 touchesEnded 方法。

if([touch view] == swipeEnd)

不管我怎么做都是假的。

有人给点建议吗?

谢谢!


解决方案


编辑 touchesEnded 方法:
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event{
if ([self.view hitTest:[[touches anyObject] locationInView:self.view] withEvent:event] == SwipeEnd) {
    if (gestureStartPointTouched == YES) {
        [TextField setText:@"Success"];
    }
}

【问题讨论】:

    标签: ios objective-c cocoa-touch uiview uikit


    【解决方案1】:

    触摸的视图永远不会改变,如果它从 swipeBegin 开始,那将永远是它的视图。如果您想找出它的结束位置,请使用 hitTest:withEvent: 和触摸的结束位置,这将返回您正在寻找的视图。

    【讨论】:

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