Ios UIView拖放并释放
我有一个可以拖动的视图。现在,我希望当我停止拖动它时,视图会变得轻松,这样我会有一种更自然的感觉 有人有主意吗Ios UIView拖放并释放,ios,objective-c,uiview,Ios,Objective C,Uiview,我有一个可以拖动的视图。现在,我希望当我停止拖动它时,视图会变得轻松,这样我会有一种更自然的感觉 有人有主意吗 - (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event { UITouch *touch = [touches anyObject]; CGPoint location = [touch locationInView:self]; CGPoint previous = [touch prev
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event
{
UITouch *touch = [touches anyObject];
CGPoint location = [touch locationInView:self];
CGPoint previous = [touch previousLocationInView:self];
if (!CGAffineTransformIsIdentity(self.transform)) {
location = CGPointApplyAffineTransform(location, self.transform);
previous = CGPointApplyAffineTransform(previous, self.transform);
}
self.frame = CGRectOffset(self.frame,
(location.x - previous.x),
(location.y - previous.y));
}
干杯我建议在视图上使用UIPangestureRecognitor来执行拖动。
您可以通过[Receignizer TranslationView:yourview]获取翻译,并通过[Receignizer VelocityView:yourview]获取速度。为拖动效果应用平移,并使用速度创建所需的减速动画。如果拖动停止,尝试查看隐藏的动画?否视图仍应显示表示在拖动停止后尝试在视图中添加动画?是。例如,如果你轻弹视图,它应该只是减缓减速使用touchesend方法并在视图上添加动画。