2010-04-26 53 views
0

其实我有一个滚动视图。我正在使用30个按钮。我的要求是什么我需要重新排列按钮。就像,当我触摸任何按钮,它应该与我们的触摸选择。我们在滚动视图中移动的位置应该随着触摸移动。在我结束触摸之后,按钮应该交换。任何人都可以帮我解决这个问题.........我们不能使用touchesBegan,touchesMoved,touchesEnded进行scrollview吗?

+0

你的要求是什么部分你有问题? – Vladimir 2010-04-26 12:59:29

回答

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) 

} 
0

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

http://github.com/facebook/three20

相关问题