【发布时间】:2014-08-30 17:17:43
【问题描述】:
我想让 UIView 在触摸后离开屏幕并在触摸后稍作延迟返回。到目前为止:
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if ([touch view] == myMainView)
{
[disappearingView.layer removeAllAnimations];
[UIView animateWithDuration:0.5
delay:0
usingSpringWithDamping:0.7
initialSpringVelocity:0.2
options:UIViewAnimationOptionBeginFromCurrentState
animations:^
{
disappearingView.transform = CGAffineTransformMakeScale(0, 0);
}
completion:^(BOOL finished)
{
}];
}
}
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{
UITouch *touch = [[event allTouches] anyObject];
if ([touch view] == myMainView)
{
[UIView animateWithDuration:0.5
delay:1
usingSpringWithDamping:0.7
initialSpringVelocity:0.2
options:UIViewAnimationOptionBeginFromCurrentState
animations:^
{
disappearingView.transform = CGAffineTransformMakeScale(1, 1);
}
completion:^(BOOL finished)
{
}];
}
}
到目前为止,上述代码运行良好。但是,如果用户在 1 秒延迟到期之前抬起手指并再次触摸,即使触摸向下,消失的视图仍会返回。如果随意上下触碰,动画会非常不一致。
我希望视图仅在 1 秒后返回,并且根本没有任何触摸。
【问题讨论】:
标签: ios animation uiview touch