【发布时间】:2014-07-15 09:13:32
【问题描述】:
我正在考虑在 iOS 上使用 Google Map 街景图钉拖放系统。用户从另一个视图(比如 UINavigationBar)中选择一个图钉并将其拖动到地图上的某个位置,然后放下它。
我有点迷失了。您是否有此类交互的工作流程?
【问题讨论】:
标签: ios drag-and-drop mkmapview mkannotationview
我正在考虑在 iOS 上使用 Google Map 街景图钉拖放系统。用户从另一个视图(比如 UINavigationBar)中选择一个图钉并将其拖动到地图上的某个位置,然后放下它。
我有点迷失了。您是否有此类交互的工作流程?
【问题讨论】:
标签: ios drag-and-drop mkmapview mkannotationview
这是一项相当复杂的任务,但可以分为几个简单的步骤。
-(void) touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
_originalPosition = self.view.center;
_touchOffset = CGPointMake(self.view.center.x-position.x,self.view.center.y-position.y);
}
-(void) touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [touches anyObject];
CGPoint position = [touch locationInView: self.view.superview];
[UIView animateWithDuration:.001
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
self.view.center = CGPointMake(position.x+_touchOffset.x, position.y+_touchOffset.y);
}
completion:^(BOOL finished) {}];
}
-(void) touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
CGPoint positionInView = [touch locationInView:self.view];
CGPoint newPosition;
if (CGRectContainsPoint(_desiredView.frame, positionInView)) {
newPosition = positionInView;
// _desiredView is view where the user can drag the view
} else {
newPosition = _originalPosition;
// its outside the desired view so lets move the view back to start position
}
[UIView animateWithDuration:0.4
delay:0.0
options:UIViewAnimationOptionCurveEaseInOut
animations:^ {
self.view.center = newPosition
// to
}
completion:^(BOOL finished) {}];
}
希望它为您指明正确的方向。
【讨论】: