【发布时间】:2013-06-07 04:44:30
【问题描述】:
我有一个 UILabel,我在其中添加了一个 GestureRecognizer。我可以在屏幕上很好地拖动它,但我想要做的是当标签在一个区域内时,我希望它停止拖动并让它平滑地移动到该区域内的指定点。
因此,如果它的 x 值大于 150,则将其移动到 200 的 x 和 150 的 y
它确实有效,但它弹出到该位置,而不是平滑地移动到该位置。
这是我的拖动方法:
- (void)labelDragged:(UIPanGestureRecognizer *)gesture {
UILabel *label = (UILabel *)gesture.view;
CGPoint translation = [gesture translationInView:label];
// move label
label.center = CGPointMake(label.center.x + translation.x,
label.center.y + translation.y);
[gesture setTranslation:CGPointZero inView:label];
if (label.center.x > 150){
[label setUserInteractionEnabled:NO];
[UIView animateWithDuration:1.5 animations:^{
label.center = CGPointMake(200 , 150);
}];
}
}
任何帮助将不胜感激。我是使用动画和点的新手。
【问题讨论】:
标签: ios xcode animation uilabel