UIDynamics를 사용하는 뷰에서 뷰를 위치에 애니메이션으로 표시하려고합니다. Core Animation 애니메이션과 UIDynamics 사이의 상호 작용에 대해서는 명확하지 않지만 이해할 수없는 일이 일어나고 있습니다.UIDynamicAnimator와 [UIView animateWithDuration :] 간의 상호 작용
단일보기, 레이블,보기의 아래쪽 중간에서 시작하는보기 컨트롤러가있는 테스트 프로젝트가 있고 맨 위 중간에 동작을 애니메이션하려고합니다.
// Create the label
UILabel *label = [[UILabel alloc] initWithFrame:CGRectMake(160, 400, 100, 50)];
label.text = @"hello";
[self.view addSubview:label];
// Set up the animator and collision
self.animator = [[UIDynamicAnimator alloc] initWithReferenceView:self.view];
UICollisionBehavior *collisionBehaviour = [[UICollisionBehavior alloc] initWithItems:@[ label ]];
[collisionBehaviour addBoundaryWithIdentifier:@"wall"
fromPoint:CGPointMake(0, 50)
toPoint:CGPointMake(320, 50)];
[self.animator addBehavior:collisionBehaviour];
// Animate the label
[UIView animateWithDuration:1.0
animations:^{
label.frame = CGRectMake(160, 100, 320, 100);
}];
이것은 단순히 내 애니메이션의 시작 또는 끝 위치 근처에있는보기 상단의 선 경계입니다. 버튼의 초기 위치로의 애니메이션에 왜 영향을 주는지는 모르겠지만 그렇습니다.
addBehaviour : call을 주석 처리하면 애니메이션이 제대로 작동합니다. 그러나 비헤이비어를 추가하면 애니메이션이 잘못된 위치로 이동합니다. 나는 왜 그런지 이해하지 못한다.