Ipad 在旋转过程中忽略CABASICANIATION
我有一个UIView,它在layoutSubviews方法中根据iPad的方向重新定位其子视图。在layoutSubviews方法中,我有一个CABasicAniamtion,用于设置子视图重新定位的动画。动画设置为特定的持续时间,但此持续时间将被忽略,并立即进行重新定位。我知道动画正在启动,因为我看到正在启动AnimationDidStart和AnimationDidStop方法。我知道这与UIView的CALayers有关,但我在web上找不到任何解释如何修复此问题的内容。任何帮助都将不胜感激Ipad 在旋转过程中忽略CABASICANIATION,ipad,animation,core-animation,uiviewanimation,Ipad,Animation,Core Animation,Uiviewanimation,我有一个UIView,它在layoutSubviews方法中根据iPad的方向重新定位其子视图。在layoutSubviews方法中,我有一个CABasicAniamtion,用于设置子视图重新定位的动画。动画设置为特定的持续时间,但此持续时间将被忽略,并立即进行重新定位。我知道动画正在启动,因为我看到正在启动AnimationDidStart和AnimationDidStop方法。我知道这与UIView的CALayers有关,但我在web上找不到任何解释如何修复此问题的内容。任何帮助都将不胜感
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];
}
}
我想知道,当调用LayoutSubview时,它是否会被忽略,因为已经有一个动画事务正在进行中。您可以尝试确认的一件事是重写-didRotateFromInterfaceOrientation并从那里调用LayoutSubview。然后查看视图是否具有动画效果
- (void) didRotateFromInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
// [self layoutSubviews];
// Give it a second to settle after the rotation and then call
// layoutSuviews explicitly.
[self performSelector:@selector(layoutSubviews) withObject:nil afterDelay:1.0f];
}
需要考虑的另一件事是,由于您仅为UIView层的位置设置动画,因此可以使用UIView动画而不是显式动画。比如:
if([[UIDevice currentDevice] orientation] == UIDeviceOrientationPortrait || [[UIDevice currentDevice] orientation] == UIDeviceOrientationPortraitUpsideDown)
{
NSLog(@"Orientation: Portrait");
//Hide icon
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.7f];
[iconImageView setCenter:iconThinPosition];
[textImageView setCenter:textThinPosition];
[UIView commitAnimations];
}
else if([[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeLeft || [[UIDevice currentDevice] orientation] == UIDeviceOrientationLandscapeRight)
{
NSLog(@"Orientation: Landscape");
// Show Icon
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:2.7f];
[iconImageView setCenter:iconShownPosition];
[textImageView setCenter:textShownPosition];
[UIView commitAnimations];
}