[英]Execute animation of subview subclass
我有一个名为ParentViewController的UIViewController。 我有一个名为CustomView的UIView自定义类。 它包括一些ImageView和执行动画的功能。
CustomView.h
@interface CustomView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *human;
@property (weak, nonatomic) IBOutlet UIImageView *shadow;
+ (id)CustomView;
- (void)executeAnimation;
@end
在CustomView.mi中,如下所示执行executeAnimation:
-(void)executeAnimation{
self.animation1InProgress = YES;
[UIView animateKeyframesWithDuration:3.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
self.human.frame = CGRectMake(self.human.frame.origin.x, self.human.frame.origin.y + 300, self.human.frame.size.width, self.human.frame.size.height);
} completion:^(BOOL finished){
self.animation1InProgress = NO;
}];
}
现在在ParentViewController.m中,我添加没有任何动画的CustomView
//init custom
customView = [CustomView initCustomView];
[self.view addSubview:centerLocationView];
这段代码可以。 我可以初始化并添加Subview到ParentViewController。 但是每当我想执行有关CustomView的动画时。 我在ParentViewController.m中调用以下代码:
[customView executeAnimation];
父视图没有任何更改。 有人知道在ParentViewController上执行此动画的方法吗?
预先感谢。
如果您确实想使用+[UIView animateKeyframesWithDuration:delay:options:animations:completion:]
,则应将关键帧添加到animations
块中:
-(void)executeAnimation{
self.animation1InProgress = YES;
[UIView animateKeyframesWithDuration:3.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
[UIView addKeyframeWithRelativeStartTime:0.0 relativeDuration:1.0 animations:^{
self.human.frame = CGRectMake(self.human.frame.origin.x, self.human.frame.origin.y + 300, self.human.frame.size.width, self.human.frame.size.height);
}];
} completion:^(BOOL finished){
self.animation1InProgress = NO;
}];
}
否则,只需使用[UIView animateWithDuration:animations:completion:]
:
-(void)executeAnimation{
self.animation1InProgress = YES;
[UIView animateWithDuration:3.0 delay:0.0 options:UIViewAnimationCurveLinear animations:^{
self.human.frame = CGRectMake(self.human.frame.origin.x, self.human.frame.origin.y + 300, self.human.frame.size.width, self.human.frame.size.height);
} completion:^(BOOL finished){
self.animation1InProgress = NO;
}];
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.