我有一个 UIView,它在 layoutSubviews 方法中根据 iPad 的方向重新定位其子视图。在 layoutSubviews 方法中,我有一个 CABasicAniamtion,它应该为子视图的重新定位设置动画。动画被设置为特定的持续时间,但这个持续时间被忽略并且重新定位立即发生。我知道动画正在触发,因为我看到 AnimationDidStart 和 AnimationDidStop 方法被触发。我知道这与 UIView 的 CALayers 有关,但我在网上找不到任何东西来解释如何解决这个问题。任何帮助,将不胜感激。
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{
NSLog(@"Orientation: Portrait");
//Hide icon
CABasicAnimation *iconAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
iconAnimation.fromValue = [NSValue valueWithCGPoint:[iconImageView center]];
iconAnimation.toValue = [NSValue valueWithCGPoint:iconThinPosition];
iconAnimation.duration = 2.7f;
iconAnimation.autoreverses = NO;
iconAnimation.repeatCount = 1;
iconAnimation.delegate = self;
[iconImageView.layer addAnimation:iconAnimation forKey:@"position"];
//[iconImageView setCenter:iconThinPosition];
[iconImageView.layer setPosition:iconThinPosition];
//[iconImageView setTransform: CGAffineTransformIdentity];
CABasicAnimation *textAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
textAnimation.fromValue = [NSValue valueWithCGPoint:[textImageView center]];
textAnimation.toValue = [NSValue valueWithCGPoint:textThinPosition];
textAnimation.duration = 2.7f;
textAnimation.autoreverses = NO;
textAnimation.repeatCount = 1;
textAnimation.delegate = self;
[textImageView.layer addAnimation:textAnimation forKey:@"position"];
[textImageView.layer setPosition:textThinPosition];
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"Orientation: Landscape");
// Show Icon
CABasicAnimation *iconAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
iconAnimation.fromValue = [NSValue valueWithCGPoint:[iconImageView center]];
iconAnimation.toValue = [NSValue valueWithCGPoint:iconShownPosition];
iconAnimation.duration = 2.7f;
iconAnimation.autoreverses = NO;
iconAnimation.repeatCount = 1;
iconAnimation.delegate = self;
[iconImageView.layer addAnimation:iconAnimation forKey:@"position"];
[iconImageView.layer setPosition:iconShownPosition];
CABasicAnimation *textAnimation = [CABasicAnimation animationWithKeyPath:@"position"];
textAnimation.fromValue = [NSValue valueWithCGPoint:[textImageView center]];
textAnimation.toValue = [NSValue valueWithCGPoint:textShownPosition];
textAnimation.duration = 2.7f;
textAnimation.autoreverses = NO;
textAnimation.repeatCount = 1;
textAnimation.delegate = self;
[textImageView.layer addAnimation:textAnimation forKey:@"position"];
[textImageView.layer setPosition:textShownPosition];
}
}