【问题标题】:Can't we use touchesBegan,touchesMoved,touchesEnded for a scrollview?我们不能使用 touchesBegan、touchesMoved、touchesEnded 作为滚动视图吗?
【发布时间】:2010-04-26 12:56:56
【问题描述】:

实际上我有一个滚动视图。我使用的是 30 个按钮。我的要求是我需要重新排列按钮。就像,当我触摸任何按钮时,应该用我们的触摸来选择它。并且无论我们在滚动视图中移动到哪里,它都应该随着我们的触摸而移动。在我结束触摸后,应该交换按钮。任何人都可以帮助我解决这个问题............

【问题讨论】:

  • 您的哪一部分需求有问题?

标签: objective-c uiscrollview touch


【解决方案1】:

您可以执行此操作,但需要做很多工作。您需要下一个:
1. 创建 UIControl 子类作为您的按钮。
2. 覆盖所有的 touches* 方法。
3.实现对标准uicontrol行为+移动行为的支持。

#pragma mark -
#pragma mark Touches delegate methods

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {

    UITouch *touch = [touches anyObject];
    [self performSelector:@selector(delayedTouchBeging:) withObject:touch afterDelay:0.15];

    [super touchesBegan:touches withEvent:event];

}


- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if ( dragging ) {
        // move your view in new position here      
    } else {
        [super touchesMoved:touches withEvent:event];       
    }

}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event {

    if ( dragging ) {

        // Do other stuff if you need

    } else {
        [super touchesEnded:touches withEvent:event];
    }

    dragging = NO;
    [NSObject cancelPreviousPerformRequestsWithTarget:self];

}


- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event {
    [self touchesEnded:touches withEvent:event];
}

- (void) delayedTouchBeging:(UITouch*) touch {
    dragging = YES;

    [self cancelTrackingWithEvent:nil];

    // Do here stuff about begin moving (animation, etc)

}

【讨论】:

    【解决方案2】:

    您可能想了解他们如何将“启动器”代码作为免费提供的three20 代码目录的一部分。他们做的正是这样的事情(并模仿 iPhone 应用程序视图,您可以在其中移动或删除应用程序)。

    http://github.com/facebook/three20

    【讨论】:

      猜你喜欢
      • 2013-01-29
      • 1970-01-01
      • 1970-01-01
      • 2023-03-09
      • 1970-01-01
      • 1970-01-01
      • 2011-03-21
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多