我们不能使用touchesBegan,touchesMoved,touchesEnded进行滚动视图吗?

时间:2010-04-26 12:56:57

标签: objective-c uiscrollview touch

其实我有一个滚动视图。我正在使用30个按钮。我的要求是什么,我需要重新排列按钮。就像,当我触摸任何按钮时,应该通过触摸选择它。如果我们在滚动视图中移动,它应该随着我们的触摸移动。在我结束触摸后,应该交换按钮。任何人都可以帮助我.........

2 个答案:

答案 0 :(得分:0)

你可以做这个行为,但是有很多工作要做。你需要下一个:
1.创建将成为按钮的UIControl子类 2.覆盖所有接触*方法。
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)

}

答案 1 :(得分:0)

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

http://github.com/facebook/three20

相关问题