[英]iPhone drag/drop
試圖為iPhone應用程序發生一些基本的拖放功能。
我目前嘗試執行此操作的代碼如下:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
self.center = location;
}
此代碼具有觸摸的UIView閃爍的結果,同時它跟隨觸摸。 稍微玩了一下之后,我也注意到UIView似乎從屏幕上的0,0位置閃爍到當前觸摸的位置。
我有什么想法我做錯了嗎?
需要在superview的坐標系中指定center屬性,但是您已根據子視圖詢問觸摸事件的位置。 而是根據superview的坐標請求它們,如下所示:
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview]; // <--- note self.superview
self.center = location;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.