2014-07-12 5 views
1

는 내가 다른 질문에서 발견 된이 기능을 사용하여보기로 시차 효과를 적용 : 그것은 잘 작동UIInterpolatingMotionEffect가 UIView의 프레임을 변경하지 않는 이유는 무엇입니까?

const static CGFloat kCustomIOS7MotionEffectExtent = 10.0; 

- (void)applyMotionEffects:(UIView *)YOUR_VIEW 
{ 
    if (floor(NSFoundationVersionNumber) <= NSFoundationVersionNumber_iOS_6_1) { 
     return; 
    } 
    UIInterpolatingMotionEffect *horizontalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.x" 
                            type:UIInterpolatingMotionEffectTypeTiltAlongHorizontalAxis]; 
    horizontalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent); 
    horizontalEffect.maximumRelativeValue = @(kCustomIOS7MotionEffectExtent); 
    UIInterpolatingMotionEffect *verticalEffect = [[UIInterpolatingMotionEffect alloc] initWithKeyPath:@"center.y" 
                            type:UIInterpolatingMotionEffectTypeTiltAlongVerticalAxis]; 
    verticalEffect.minimumRelativeValue = @(-kCustomIOS7MotionEffectExtent); 
    verticalEffect.maximumRelativeValue = @(kCustomIOS7MotionEffectExtent); 
    UIMotionEffectGroup *motionEffectGroup = [[UIMotionEffectGroup alloc] init]; 
    motionEffectGroup.motionEffects = @[horizontalEffect, verticalEffect]; 
    [YOUR_VIEW addMotionEffect:motionEffectGroup]; 
} 

을,하지만 내가보기의 프레임을 로그인 한 후 발견하는 것은 변경하지 않습니다. 그들은 어떻게 그랬을까요? 특별한 이유가 있습니까? 시차 효과가 발생하면 실제 뷰 위치가 변경되기 때문에 개발을 계속하는 것이 훨씬 쉬워 지지만 실제로는 이해가되지 않습니다.

답변

2

대부분의 애니메이션에서와 마찬가지로 UIInterpolatingMotionEffectlayer (모델 레이어)의 presentationLayer을 사용하여 애니메이션을 수행하기 때문입니다. 애트리뷰트는 일반적으로 애니메이션이 실제로 완료되면 모델 레이어에 적용됩니다.이 경우 완성은 실제로 모션 효과가 끝나면 시작 위치로 되돌려 놓기 때문에 실제 모델 레이어는 결코 변경되지 않습니다.

프리젠 테이션 레이어의 속성을 확인해보십시오.

CALayer *presentationLayer = [myView.layer presentationLayer]; 

CGRect frame = presentationLayer.frame; 
CGPoint position = presentationLayer.position; 
관련 문제