나는 ParentViewController라는 UIViewController가 있습니다. 그리고 CustomView라는 UIView 사용자 지정 클래스가 있습니다. 그것은 ImageView와 애니메이션을 실행하는 함수를 포함합니다. 하위 뷰 하위 클래스의 애니메이션 실행
-(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에, 내가 어떤 애니메이션
//init custom
customView = [CustomView initCustomView];
[self.view addSubview:centerLocationView];
하지 않고있는 CustomView를 추가
다음과 같은 CustomView.h
@interface CustomView : UIView
@property (weak, nonatomic) IBOutlet UIImageView *human;
@property (weak, nonatomic) IBOutlet UIImageView *shadow;
+ (id)CustomView;
- (void)executeAnimation;
@end
그리고 CustomView.mi의 AVE의 executeAnimation에서
이 코드는 정상입니다. 나는 초기화하고 ParentViewController에 AddSubview를 할 수있다. 하지만 언제든지 CustomView에 대한 애니메이션을 실행하고 싶습니다. ParentViewController.m에서 다음 코드를 호출합니다.
[customView executeAnimation];
부모보기에서 변경된 사항은 없습니다. ParentViewController에서이 애니메이션을 실행하는 방법을 아는 사람이 있습니까?
감사합니다.
감사합니다. 시도하고 ParentView는 애니메이션이 실행 된 것을 볼 수 있습니다. 고맙습니다. 그러나 addKeyframeWithRelativeStartTime 및 relativeDuration에 대해 설명해 주시겠습니까? –
또한이 경우 애니메이션 실행 완료 후. human.frame이 원래 위치로 재설정됩니다. 하지만 이제는 그렇지 않습니다 –
'animations' 블록 안에서 애니메이션화 가능한 속성을 업데이트하면 실제로는 표현 계층이 아닌 애니메이션 계층을 업데이트합니다. 'self.human.frame'을 올바른 값으로 다시 설정해야하지만'animations' 블록 안에 설정해야합니다. 자세한 내용은이 기사를 참조하십시오 : [애니메이션 설명] (http://www.objc.io/issue-12/animations-explained.html) –