转换无法执行两次 [英] Transformation unable to perform twice

查看:61
本文介绍了转换无法执行两次的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有这个功能,

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

当我第一次调用它时,它确实起作用了.

When i call it first time, it did worked.

但是,我在同一视图中再次调用,它无法执行并停留在该视图中.

However, i call again within same view, it cannot perform and stuck there.

隐藏的工作

-过渡无效

-旋转不起作用

-nslog工作

为什么第二次会变成这样?

Why second time will become like this?

更新

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

这就是我调用该函数的方式.但是,还是一样.

This is how I call the function. However, it still same.

推荐答案

在这段代码中,您更改了转换

in this bit of code your changed the transform

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

例如,考虑您将star1初始转换为x, 现在,您需要进行一些转换计算....

for eg consider your having the star1 initial transform is x , now your doing some calculation for transform....

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

然后

您将星号x的变换更改为y ...

your changed the transform of star x to y...

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

现在您的恒星变换将变得正常...

now your star transform will become y okay...

再次通过调用来执行此代码,因此您的初始星形变换为y,而等式变换为y,因此不需要,您也看不到任何结果...

again doing this code by call again so again your initial star transform is y and your equating transform to y so no need and u didn't see any of the result...

y = y,所以没有结果....

y=y so no result....

因此需要更改某些逻辑或您想要的逻辑,但这是一个主意...

So need to change some logic like this or some what you want but this is an idea...

第一个变化:您需要存储每颗恒星的变换,因此需要一些变换类型的变量集...

1st change: you need to store the transform of each star so you need some set of variables of type transform...

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

第二个更改:您需要在加载后的视图中保存星星的初始变换....

2nd change:you need to save the initial transform of stars in the view did load....

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

我希望这会对您有所帮助....

i hope this will help you....

请尝试使用此代码进行旋转动画.....

Hi try this code for spin animation.....

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

这篇关于转换无法执行两次的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆