[英]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.