0

layoutSubviews メソッドで iPad の向きに基づいてサブビューを再配置する UIView があります。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];
    }
}
4

1 に答える 1

1

layoutSubviewsが呼び出されたときに、すでにアニメーショントランザクションが進行中であるため、無視されていないのではないかと思います。これを確認するために試みることができる1つのことは、-didRotateFromInterfaceOrientationをオーバーライドし、そこからlayoutSubviewsを呼び出すことです。次に、ビューがアニメーション化されるかどうかを確認します。

- (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];
}

もう1つ考えておくべきことは、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];

    }
于 2010-10-05T18:16:42.920 に答える