iPhone拖放 [英] iPhone drag/drop

查看:85
本文介绍了iPhone拖放的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述



我目前正在尝试这样做的代码如下:

$ (NSSet *)触摸与事件:(UIEvent *)事件
{
UITouch * touch = [touches anyObject];

CGPoint location = [touch locationInView:self];
self.center = location;
}

此代码具有触摸的UIView闪烁的结果,同时触摸周围。在玩了一下之后,我也注意到,UIView似乎从屏幕上的0,0位置闪烁到当前感兴趣的位置。



任何想法我做错了?

解决方案

中心属性需要在超级视图的坐标系中指定,但是在您的子视图中询问该位置的触摸事件。而是根据superview的坐标来询问他们,如下所示:

   - (void)touchesMoved:(NSSet *)touchEvent: (UIEvent *)事件{
UITouch * touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview]; //< --- note self.superview

self.center = location;
}


Trying to get some basic drag/drop functionality happening for an iPhone application.

My current code for trying to do this is as follows:

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
    UITouch *touch = [touches anyObject];

    CGPoint location = [touch locationInView:self];
    self.center = location;
}

This code has the result of a the touched UIView flickering while it follows the touch around. After playing around with it a bit, I also noticed that the UIView seemed to flicker from the 0,0 position on the screen to the currently touched location.

Any ideas what I'm doing wrong?

解决方案

The center property needs to be specified in the coordinate system of the superview, but you've asked the touch event for the location in terms of your subview. Instead ask for them based on the superview's coordinates, like this:

- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
    UITouch *touch = [touches anyObject];   
    CGPoint location = [touch locationInView:self.superview]; // <--- note self.superview

    self.center = location;
}

这篇关于iPhone拖放的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆