2012-04-20 2 views
11

그림자와 UIImageView 하위 뷰가있는 UIView이 있습니다.부드럽게 회전하고 그림자가있는 UIView의 크기를 변경하십시오.

iPad를 회전 할 때보기의 크기를 조정하고 willRotateToInterfaceOrientation 콜백에서이 작업을 수행하려고합니다.

UIView의 그림자를 기본 방식으로 설정하면 회전이 매우 고르지 않습니다. 그림자 설정 layer.shadowPath를 설정하는 방법에 대한 다른 사람들의 제안을 원합니다.

[UIView animateWithDuration:animations]을 사용하여 프레임 크기 변경에 애니메이션 효과를 적용하고 동일한 블록에 새로운 shadowPath을 설정했지만 섀도우 패스가 새 크기로 스냅됩니다.

그리고 애니메이션 블록에서 레이어의 shadowPath를 변경하지 않으면 변경되지 않습니다.

내가 수행 한 몇 가지 검색 결과에서 레이어 속성의 변경 사항을 CABasicAnimation으로 변경해야합니다.

그래서 "UIView의 프레임 크기와 레이어 변경을 동시에 애니메이트하는 방법은 무엇입니까?"

답변

8

희망보다 조금 많은 코드가 있지만 작동해야합니다.

CGFloat animationDuration = 5.0; 

    // Create the CABasicAnimation for the shadow 
    CABasicAnimation *shadowAnimation = [CABasicAnimation animationWithKeyPath:@"shadowPath"]; 
    shadowAnimation.duration = animationDuration; 
    shadowAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]; // Match the easing of the UIView block animation 
    shadowAnimation.fromValue = (id)self.shadowedView.layer.shadowPath; 

    // Animate the frame change on the view 
    [UIView animateWithDuration:animationDuration 
         delay:0.0f 
         options:UIViewAnimationCurveEaseInOut 
        animations:^{ 
        self.shadowedView.frame = CGRectMake(self.shadowedView.frame.origin.x, 
                  self.shadowedView.frame.origin.y, 
                  self.shadowedView.frame.size.width * 2., 
                  self.shadowedView.frame.size.height * 2); 
        } completion:nil]; 

    // Set the toValue for the animation to the new frame of the view 
    shadowAnimation.toValue = (id)[UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath; 

    // Add the shadow path animation 
    [self.shadowedView.layer addAnimation:shadowAnimation forKey:@"shadowPath"]; 

    // Set the new shadow path 
    self.shadowedView.layer.shadowPath = [UIBezierPath bezierPathWithRect:self.shadowedView.bounds].CGPath; 
관련 문제