0

私はこの機能を持っています、

-(void)transitionstar{
star.hidden = NO;
star2.hidden = NO;
star3.hidden = NO;
star4.hidden = NO;
star5.hidden = NO;
star6.hidden = NO;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.4f];
[UIView animateWithDuration:0.0 animations:^{
    CGAffineTransform scale = CGAffineTransformMakeScale(1, 1);
    CGAffineTransform rotate = CGAffineTransformMakeRotation(360.0);
     CGAffineTransform rotate2 = CGAffineTransformMakeRotation(-360.0);
     CGAffineTransform rotate3 = CGAffineTransformMakeRotation(-720.0);
     CGAffineTransform rotate4 = CGAffineTransformMakeRotation(720.0);
     CGAffineTransform rotate5 = CGAffineTransformMakeRotation(1080.0);
     CGAffineTransform rotate6 = CGAffineTransformMakeRotation(-1080.0);
    CGAffineTransform translate = CGAffineTransformMakeTranslation(-800, -800);
     CGAffineTransform translate2 = CGAffineTransformMakeTranslation(600, -600);
     CGAffineTransform translate3 = CGAffineTransformMakeTranslation(400, 400);
     CGAffineTransform translate4 = CGAffineTransformMakeTranslation(-200, 200);
     CGAffineTransform translate5 = CGAffineTransformMakeTranslation(900, -300);
     CGAffineTransform translate6 = CGAffineTransformMakeTranslation(-200, 500);

    CGAffineTransform transform =  CGAffineTransformConcat(translate, scale);
    transform = CGAffineTransformConcat(transform, rotate);

    CGAffineTransform transform2 =  CGAffineTransformConcat(translate2, scale);
    transform2 = CGAffineTransformConcat(transform2, rotate2);

    CGAffineTransform transform3 =  CGAffineTransformConcat(translate3, scale);
    transform3 = CGAffineTransformConcat(transform3, rotate3);

    CGAffineTransform transform4 =  CGAffineTransformConcat(translate4, scale);
    transform4 = CGAffineTransformConcat(transform4, rotate4);
    CGAffineTransform transform5 =  CGAffineTransformConcat(translate5, scale);
    transform5 = CGAffineTransformConcat(transform5, rotate5);
    CGAffineTransform transform6 =  CGAffineTransformConcat(translate6, scale);
    transform6 = CGAffineTransformConcat(transform6, rotate6);

    star.transform = transform;
    star2.transform = transform2;
    star3.transform = transform3;
    star4.transform = transform4;
    star5.transform = transform5;
    star6.transform = transform6;
}
                 completion:^(BOOL finished){
                     if (finished) {
                         star.hidden = YES;
                         star2.hidden = YES;
                         star3.hidden = YES;
                         star4.hidden = YES;
                         star5.hidden = YES;
                         star6.hidden = YES;
                     }
                 }];
[UIView commitAnimations];
}

初めて呼び出すと、うまくいきました。

ただし、同じビュー内で再度呼び出すと、実行できず、そこでスタックします。

・隠し仕事

-トランジションが機能しない

・回転が効かない

-nslog作業

なぜ2回目はこうなるのか?

アップデート

if(!positionrepeat)
        {
            //Display Correct IMAGE;
            [isrepeat addObject:[NSNumber numberWithInt:positionvalue]];
            //soundeffect = [self createSoundID: @"correct"];
            //AudioServicesPlaySystemSound(soundeffect);
            [self displayresulttext:@"correct"];
            [self.view setNeedsDisplay];
            [self transitionstar];
            correct++;
            completed.text = [NSString stringWithFormat:@"%d", correct];
            [self result];
        }

これが私が関数を呼び出す方法です。しかし、それはまだ同じです。

4

2 に答える 2

0

上記のメソッドは、UIView から派生したクラス内で機能していると想定しています。

この仮定が正しければ、ビューを再描画する必要があるときにメソッドを呼び出すことができます。

ビューを再描画するには、次のように setNeedsDisplay メソッドを呼び出す必要があります。

[myCustomView setNeedsDisplay];
于 2012-09-10T02:23:51.967 に答える
0

このコードでは、変換を変更しました

  star.transform = transform;
        star2.transform = transform2;
        star3.transform = transform3;
        star4.transform = transform4;
        star5.transform = transform5;
        star6.transform = transform6;

たとえば、 star1 の初期変換が x であると考えてください。今、変換の計算を行っています....

CGAffineTransform rotate = CGAffineTransformMakeRotation(360.0);
CGAffineTransform translate = CGAffineTransformMakeTranslation(-800, -800);
CGAffineTransform transform =  CGAffineTransformConcat(translate, scale);
    transform = CGAffineTransformConcat(transform, rotate);

それから

スターxの変換をyに変更しました...

star.transform = transform;//say this is y

これで、あなたのスタートランスフォームは大丈夫になります...

再び呼び出しでこのコードを実行するので、最初のスター変換は y であり、等価変換は y であるため、必要はなく、結果は表示されませんでした...

y=y なので結果なし....

したがって、このようなロジックや必要なものを変更する必要がありますが、これはアイデアです...

最初の変更: 各星の変換を保存する必要があるため、変換型の変数のセットが必要です...

  CGAffineTransform star1Initial,star2Initial,star3Initial,star4Initial,star5Initial,star6Initial;

2 番目の変更: ビューで星の初期変換を保存する必要があります。

    star1Initial=star1.transform;
    star2Initial=star2.transform;
    star3Initial=star3.transform;
    star4Initial=star4.transform;
    star5Initial=star5.transform;
    star6Initial=star6.transform;


-(void)transitionstar{
    star1.hidden = NO;
    star2.hidden = NO;
    star3.hidden = NO;
    star4.hidden = NO;
    star5.hidden = NO;
    star6.hidden = NO;

        star1.transform=star1Initial;
        star2.transform=star2Initial;
        star3.transform=star3Initial;
        star4.transform=star4Initial; 
        star5.transform=star5Initial;
        star6.transform=star6Initial;


//    [UIView beginAnimations:nil context:NULL];
//    [UIView setAnimationDuration:0.4f];
    [UIView animateWithDuration:1.0 animations:^{
        CGAffineTransform scale = CGAffineTransformMakeScale(1, 1);
        CGAffineTransform rotate = CGAffineTransformMakeRotation(360.0);
        CGAffineTransform rotate2 = CGAffineTransformMakeRotation(-360.0);
        CGAffineTransform rotate3 = CGAffineTransformMakeRotation(-720.0);
        CGAffineTransform rotate4 = CGAffineTransformMakeRotation(720.0);
        CGAffineTransform rotate5 = CGAffineTransformMakeRotation(1080.0);
        CGAffineTransform rotate6 = CGAffineTransformMakeRotation(-1080.0);
        CGAffineTransform translate = CGAffineTransformMakeTranslation(-800, -800);
        CGAffineTransform translate2 = CGAffineTransformMakeTranslation(600, -600);
        CGAffineTransform translate3 = CGAffineTransformMakeTranslation(400, 400);
        CGAffineTransform translate4 = CGAffineTransformMakeTranslation(-200, 200);
        CGAffineTransform translate5 = CGAffineTransformMakeTranslation(900, -300);
        CGAffineTransform translate6 = CGAffineTransformMakeTranslation(-200, 500);

        CGAffineTransform transform =  CGAffineTransformConcat(translate, scale);
        transform = CGAffineTransformConcat(transform, rotate);

        CGAffineTransform transform2 =  CGAffineTransformConcat(translate2, scale);
        transform2 = CGAffineTransformConcat(transform2, rotate2);

        CGAffineTransform transform3 =  CGAffineTransformConcat(translate3, scale);
        transform3 = CGAffineTransformConcat(transform3, rotate3);

        CGAffineTransform transform4 =  CGAffineTransformConcat(translate4, scale);
        transform4 = CGAffineTransformConcat(transform4, rotate4);
        CGAffineTransform transform5 =  CGAffineTransformConcat(translate5, scale);
        transform5 = CGAffineTransformConcat(transform5, rotate5);
        CGAffineTransform transform6 =  CGAffineTransformConcat(translate6, scale);
        transform6 = CGAffineTransformConcat(transform6, rotate6);

        star1.transform = transform;
        star2.transform = transform2;
        star3.transform = transform3;
        star4.transform = transform4;
        star5.transform = transform5;
        star6.transform = transform6;
    }
                     completion:^(BOOL finished){
                         if (finished) {
                             star1.hidden = YES;
                             star2.hidden = YES;
                             star3.hidden = YES;
                             star4.hidden = YES;
                             star5.hidden = YES;
                             star6.hidden = YES;
                         }
                     }];
//    [UIView commitAnimations];
}

これがあなたに役立つことを願っています....

こんにちは、スピンアニメーション用にこのコードを試してください.....

- (void) runSpinAnimationWithDuration:(CGFloat) duration;
{
    CABasicAnimation* rotationAnimation;
    int rotations=1;
    rotationAnimation = [CABasicAnimation animationWithKeyPath:@"transform.rotation.z"];
    rotationAnimation.toValue = [NSNumber numberWithFloat: M_PI * 2.0 /* full rotation*/ * rotations * duration ];
    rotationAnimation.duration = duration;
    rotationAnimation.cumulative = YES;
    rotationAnimation.repeatCount = 1.0; 
    rotationAnimation.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut];
于 2012-09-10T04:57:45.693 に答える