问题描述
我必须通过使界面元素 (UIView) 在屏幕上移动来执行动画,以便动画呈现出相同的外观从其超级视图移动到与其超级视图相邻的另一个视图。
@interface MovableElement : UIView
{
CABasicAnimation *a;
}
@end
@implementation MovableElement
-(void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%@",NsstringFromSelector(_cmd));
UITouch *t= [touches anyObject];
CGPoint p= [t locationInView:self];
a= [CABasicAnimation animationWithKeyPath:@"position"];
[a setFromValue:@(self.layer.position)];
[a setTovalue:@(p)];
[self.layer addAnimation:a forKey:@"positionAnimation"];
}
-(void)touchesMoved:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%@",NsstringFromSelector(_cmd));
UITouch *t= [touches anyObject];
CGPoint p= [t locationInView:self];
[a setTovalue:@(p)];
[self.layer setPosition:p];
}
-(void)touchesEnded:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event{
NSLog(@"%@",NsstringFromSelector(_cmd));
UITouch *t= [touches anyObject];
CGPoint p= [t locationInView:self];
self.layer.position= p;
}
@end
问题在于,当“MovableElement”对象从其位置移动时,在拖动它时,远离其父视图的位置并位于另一个视图的顶部时,它最终不再响应触摸事件。因此,在此之后不再调用上述触摸方法。因此,在此阶段之后您将无法执行任何动画;一旦“MovableElement”到达另一个视图(与 MovableElement 的父视图相邻),即。
我想知道这背后的原因。我是 Core Animations 和 CALayer 的新手。任何建议将是最受欢迎的。谢谢。
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)