Welcome to the Treehouse Community

Want to collaborate on code errors? Have bugs you need feedback on? Looking for an extra set of eyes on your latest project? Get support with fellow developers, designers, and programmers of all backgrounds and skill levels here with the Treehouse Community! While you're at it, check out some resources Treehouse students have shared here.

Looking to learn something new?

Treehouse offers a seven day free trial for new students. Get access to thousands of hours of content and join thousands of Treehouse students and alumni in the community today.

Start your free trial

iOS Build a Simple iPhone App with Objective-C Improving Our User Interface Using the ColorWheel Class

Shaun Kelly
Shaun Kelly
5,648 Points

Make the colours transition to a different colour with a fade ?

Anybody know how to make the colours transition and fade between each other and control the fade duration? My best bet is with a SKTransition but the following code example is invalid and is incompatible pointer types. So i'm not sure how to approach this?

 UIColor *randomColor = [self.colorWheel.colors objectAtIndex:[Utility randomNumberBetween:0 max:self.colorWheel.numberOfColorsInArray]];

    SKTransition *transition = [SKTransition fadeWithColor:randomColor duration:1.0];

    self.view.backgroundColor = transition;
Shaun Kelly
Shaun Kelly
5,648 Points

or is SKTransition only for transitioning between different scenes ?

Shaun Kelly
Shaun Kelly
5,648 Points

Found it haha..

- (IBAction)showFunFact {


    [UIView animateWithDuration:1.0 animations:^{

    UIColor *randomColor = [self.colorWheel.colors objectAtIndex:[Utility randomNumberBetween:0 max:self.colorWheel.numberOfColorsInArray]];


        self.view.backgroundColor = randomColor;


    self.funFactButton.tintColor = randomColor;

    }];



     self.funFactLabel.text = [self.factBook.facts objectAtIndex:[Utility randomNumberBetween:0 max:self.factBook.numberOfObjectInArray]];


}

8 Answers

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Hi Shaun, glad you got it, (it's good to see people try to figure out issues them selves) did you just add the following code what was already there?

[UIView animateWithDuration:1.0 animations:^{

 UIColor *randomColor = [self.colorWheel.colors objectAtIndex:[Utility randomNumberBetween:0 max:self.colorWheel.numberOfColorsInArray]];


        self.view.backgroundColor = randomColor;


    self.funFactButton.tintColor = randomColor;

    }];
Shaun Kelly
Shaun Kelly
5,648 Points

I got a it of help from stack overflow but i thought of some of the code myself

Shaun Kelly
Shaun Kelly
5,648 Points

I was wondering if you could help me with a problem from one of my own projects i'm working on which is a game. When the player reaches a certain score, he/she will be awarded a medal. If the players reaches a score of 25 the first time round. Both medal animations play at the same time which is not what i want. I want the first medal animation to be played then wait until completion and then the second animation will be player after. Got any ideas ?

From the following code below i'm expecting... when the player reaches a highscore of 25 or over and if the second medal has NOT been used, it will play the firstmedal animation and then wait 10 seconds and follow it up with the secondmedal animation. But it doesn't and the waitForDuration method is defective. Both animation run at the same time??? confused! ?

 //SECOND MEDAL
    if ((_HighScore >= 25) && (self.usedSecondMedal == NO)) {


        //IF THE PREVIOUSE MEDALS HASN'T BEEN USED
        if (self.usedFirstMedal == NO) {


           // ADD THE FIRST MEDAL ANIMATION
            SKAction *firstMedal = [SKAction runBlock:^{
                [self addFirstMedal];
            }];

           //WAIT 10 SECONDS
            SKAction *wait = [SKAction waitForDuration:10.0];

            //ADD THE SECOND MEDAL ANIMATION
            SKAction *secondMedal = [SKAction runBlock:^{
                [self addSecondMedal];
            }];


            //SEQENCE TO ADD THE FIRST MEDAL, WAIT AND THEN ADD THE SECOND MEDL
            SKAction *seqence = [SKAction sequence:@[firstMedal, wait,secondMedal]];
            [self runAction:seqence];
        }



        //IF THE PREVRIOUS MEDAL HAS BEEN USED WHICH IN THIS CASE IS THE FIRSTMEDAL
        else {
            [self addSecondMedal];
        }

    }
Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Try re-writing it as:

//SECOND MEDAL
    if ((_HighScore >= 25) && (self.usedSecondMedal == nil)) {


        //IF THE PREVIOUSE MEDALS HASN'T BEEN USED
        if (self.usedFirstMedal == nil) {


           // ADD THE FIRST MEDAL ANIMATION
            SKAction *firstMedal = [SKAction runBlock:^{
                [self addFirstMedal];
            }];

           //WAIT 10 SECONDS
            SKAction *wait = [SKAction waitForDuration:10.0];

            //ADD THE SECOND MEDAL ANIMATION
            SKAction *secondMedal = [SKAction runBlock:^{
                [self addSecondMedal];
            }];


            //SEQENCE TO ADD THE FIRST MEDAL, WAIT AND THEN ADD THE SECOND MEDL
            SKAction *seqence = [SKAction sequence:@[firstMedal, wait,secondMedal]];
            [self runAction:seqence];
        }



        //IF THE PREVRIOUS MEDAL HAS BEEN USED WHICH IN THIS CASE IS THE FIRSTMEDAL
        else {
            [self addSecondMedal];
        }

    }

I'm not saying that it will fix it, but I've never seen a line written like yours. I'm also wondering if this line:

[self runAction:seqence];

Should be written as:

[self runAction:@"seqence"];

I don't know much about writing game apps so I based this off other things I know.

Shaun Kelly
Shaun Kelly
5,648 Points

thanks but all doesn't work.. first error says "Comparison between pointer and integer ('int' and 'void')". And second error is saying incompatible pointer types sending 'NSString' to parameter of type 'SKAction'

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

Are those the errors that you got from my code? Because in the [self runAction:sequence] I did create an NSString. And what lines are the errors on?

Shaun Kelly
Shaun Kelly
5,648 Points

yes and where is the string, i don't see any string in the code ?

Caleb Kleveter
MOD
Caleb Kleveter
Treehouse Moderator 37,862 Points

If you changed:

[self runAction:seqence];

to:

[self runAction:@"seqence"];

you created a string out of "seqence". BTW, should"seqence" be spelled as "sequence"?

As I thought about your issue I got the idea that maybe you could have the first medal appear, set a timer for nothing to happen for 10 seconds with NSTimer and then have the second medal appear as addressed in this video.