2010-08-04 45 views
1

我想在我的视图中可以拖放的对象。iPhone应用程序中的对象是如何拖动的?

当它们被放置在某个区域时,它们应该消失并且应该执行一些代码。

对象在iPhone应用程序中如何拖动?它只是一个可以启用拖动的按钮吗?

如何检测可拖动对象的位置?它会像(Psuedo)一样简单吗?

if (draggableButton1.xPosition > e.g. && draggableButton1.xPosition < e,g 
     && draggableButton1.yPosition > e.g. && draggableButton1.yPosition < e,g) { 
    do something 
} 

回答

4

当用户触摸时间以下的方法被调用的对象。

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

当触摸移动时,将调用以下方法。

- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event 

当与触摸用户端,下面的方法将被用于

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

NSSet对象包含UITouch对象包含关于屏幕上视图的触摸,其查看所有信息,位置,前位置等等。你可以检查文件。

从touchesBegan开始您的逻辑,并在touchesMoved事件中更改对象的位置。那么当用户放弃对象时,touchesEnded事件将被调用。检查touchesEnded事件中的位置并按照您的说法执行您的代码。

这三种方法可以帮助...

相关问题