我正在尝试在我的应用程序中拖动 iPhone 屏幕上的 UIImageView 。
目前我设置的拖动功能很好,拖动图像确实会在屏幕上移动它,问题是你不必拖动图像视图来移动它,你也可以拖动屏幕上的任何地方,它会移动图像。
我是这个平台的新手,所以我无法真正思考如何解决这个问题。
我当前拖动图像的代码是:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:pig];
startLocation = pt;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:pig];
CGRect frame = [pig frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[pig setFrame: frame];
}
任何帮助表示赞赏。顺便说一句,pig 是 UIImageView。
我还注意到,如果我将图像视图“猪”的用户交互设置为启用,则图像将不再可拖动,但当它未设置为启用时,则可以。
您可以尝试子类化 UIImageView 并实现touchesBegan:
and touchesMoved:
直接在上面。然后在 InterfaceBuilder 中选择 UIImageView 的子类。
替代文本 http://img.skitch.com/20090728-xetretcfubtcj7ujh1yc8165wj.jpg http://img.skitch.com/20090728-xetretcfubtcj7ujh1yc8165wj.jpg
哦,是的,现在您需要再次设置用户交互......
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系:hwhale#tublm.com(使用前将#替换为@)