【发布时间】:2009-09-26 18:23:01
【问题描述】:
我正在尝试解决 iPhone 上拖放的基本问题。这是我的设置:
- 我有一个 UIScrollView,它有一个大的内容子视图(我可以滚动和缩放它)
- 内容子视图有几个小图块作为应在其中拖动的子视图。
我的 UIScrollView 子类有这个方法:
- (UIView *)hitTest:(CGPoint)point withEvent:(UIEvent *)event {
UIView *tile = [contentView pointInsideTiles:[self convertPoint:point toView:contentView] withEvent:event];
if (tile) {
return tile;
} else {
return [super hitTest:point withEvent:event];
}
}
内容子视图有这个方法:
- (UIView *)pointInsideTiles:(CGPoint)point withEvent:(UIEvent *)event {
for (TileView *tile in tiles) {
if ([tile pointInside:[self convertPoint:point toView:tile] withEvent:event])
return tile;
}
return nil;
}
平铺视图有这个方法:
- (void)touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self.superview];
self.center = location;
}
这可行,但并不完全正确:在拖动过程中,瓷砖有时会“掉落”。更准确地说,它停止接收 touchesMoved: 调用,并且滚动视图开始滚动。我注意到这取决于拖动速度:拖动速度越快,图块“下落”的速度就越快。
关于如何让瓷砖粘在拖动的手指上的任何想法?
【问题讨论】:
-
你有这方面的样品吗?
标签: iphone objective-c