3

this example of using dynamic animators for view controller transitions을 수정 중입니다. 내가하고 싶은 일 중 하나는 iPad에서 작동하게하고 중력 전환 방향을 위에서 아래로 오른쪽에서 왼쪽으로 변경하는 것입니다. 보기 크기, 힘 적용 및 중력 방향을 기반으로 뷰 전환 시간을 계산할 수있는 방법이 있다면 에 관심이 있습니까? 즉,보기가 오른쪽 경계에 도달하고 그 경계를 벗어나는 것을 멈출 때까지의 기간입니다.iOS 뷰 컨트롤러 전환에 UIDynamicAnimator를 사용할 때 전환 지속 시간을 계산하는 방법은 무엇입니까?

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext 

내가 푸시 크기가 아이폰 화면을 위해 작동하지만, 아이 패드 화면은 "너무 느리다"인 100으로 설정했다 함께 일하고 있어요 예 :

나는에서이 정확한 시간을 반환하려면 . 내가 이해하는 바에 따르면, 화면 크기에 힘이 가해 지는데, iPad 화면은 시간이 지나면 더 강하게 움직여야합니다. 다음과 같이

그래서 나는 코드를 수정 : 작동

pushBehavior.pushDirection = CGVectorMake(1,0); 
pushBehavior.magnitude = 700.0; 
UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[toViewController.view]]; 
gravityBehavior.gravityDirection = CGVectorMake(-1.0, 0); 

,하지만 지금은 새로운 전환이 걸리는 시간을 알 수 없습니다. 기본값은 1.5 초입니다. 그러나이 값을 0.7로 설정하면 뷰가 전환을 통해 절반으로 멈추게됩니다. dynamicAnimatorDidPause : 뷰 정적 상태에 도달하면,이 라고한다

- (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext { 
    return 1.5f; 
} 


- (UIDynamicAnimator*)animateForTransitionContext:(id<UIViewControllerContextTransitioning>)transitionContext { 
    // Get the view controllers for the transition 
    UIViewController *fromViewController = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey]; 
    UIViewController *toViewController = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey]; 


    // Prepare the view of the toViewController 
    toViewController.view.frame = CGRectOffset(fromViewController.view.frame, 1.0f*fromViewController.view.frame.size.width,0); 


    // Add the view of the toViewController to the containerView 
    [[transitionContext containerView] addSubview:toViewController.view]; 

    // Create animator 
    UIDynamicAnimator *animator = [[UIDynamicAnimator alloc] initWithReferenceView:[transitionContext containerView]]; 

    // Add behaviors 
    UIGravityBehavior *gravityBehavior = [[UIGravityBehavior alloc] initWithItems:@[toViewController.view]]; 
    gravityBehavior.gravityDirection = CGVectorMake(-1.0, 0); 

    UICollisionBehavior *collisionBehavior = [[UICollisionBehavior alloc] initWithItems:@[toViewController.view]]; 


    [collisionBehavior addBoundaryWithIdentifier:@"LeftBoundary" fromPoint:CGPointMake(0,0) toPoint:CGPointMake(0.0f, fromViewController.view.frame.size.height+1)]; 


    UIDynamicItemBehavior *propertiesBehavior = [[UIDynamicItemBehavior alloc] initWithItems:@[toViewController.view]]; 
    propertiesBehavior.elasticity = 0.2; 

    UIPushBehavior *pushBehavior = [[UIPushBehavior alloc] initWithItems:@[toViewController.view] mode:UIPushBehaviorModeInstantaneous]; 
// pushBehavior.angle = 0; 
    pushBehavior.pushDirection = CGVectorMake(-1, 0); 
    pushBehavior.magnitude = 700.0; 

    [animator addBehavior:pushBehavior]; 
    [animator addBehavior:propertiesBehavior]; 
    [animator addBehavior:collisionBehavior]; 
    [animator addBehavior:gravityBehavior]; 

    return animator; 
} 
+0

나는 이것이 적어도 지금은 불가능하다고 생각합니다. 사과가 'transitionDuration'을 필요로하지 않는 전환 프로토콜을 제공하지 않는다면 –

답변

0

UIDynamicAnimator이 위임 방법이있다. 따라서 transitionContext에 대한 참조 (약한 속성과 같은)를 삽입하고 애니메이터 대리자를 self로 설정하고 completeTransition :을 호출합니다.

-(void)dynamicAnimatorDidPause:(UIDynamicAnimator *)animator 
{ 
    [self.transitionContext completeTransition:finished]; 
}