tags:

views:

19

answers:

1

HI all, i want to move a UILabel up for 5 sec and gets hidden. Something we see in games, when we get bouus or something, a text comes up ,moves up saying something "+300" etc.

How to do move UIlabel? regards

+1  A: 

Have a look at the UIView animation methods

i.e.

- (void)showScoreLabelFor:(int)score {
    // Make a label
    UILabel *scoreLabel = [UILabel alloc] initWithFrame:CGRectMake(0, 0, 100, 100)] autorelease];

    // Set it's text to the score we want to show
    [scoreLabel setText:[NSString stringWithFormat:@"%+i", score]];

    // Center it in the view
    [scoreLabel sizeToFit];
    [scoreLabel setCenter:CGPointMake([[self view] center].x, 200)];

    // Add it to the view
    [[self view] addSubview:scoreLabel];

    // Animate it up 100 pixels ver 2 seconds
    [UIView beginAnimations:nil context:nil];
    [UIView setAnimationDuration:2.0];
    CGRect frame = [scoreLabel frame];
    frame.origin.y -= 100;
    [scoreLabel setFrame:frame];
    [UIView commitAnimations];
}
deanWombourne
hey deanWombournethanks fro replycan u explain a bit wat does that code exactly do?i implemented it, but 1 am getting an label fixed at position onlyregards
shishir.bobby
Anything between __beginAnimations__ and __commitAnimations__ is animated - so if I set the y position of the label to be 100 higher it will slide the label up 100px. If you edit your question and add the code you're having trouble with I can have a look.
deanWombourne
i just need to display a text saying "+ 500"which show move in up direction and after 3-4 seconds, it should gets hides.thanks man i really appreciate ur help
shishir.bobby
I've edited my question to make it into a method that put s a label onto your viewcontrollers view and animates it up by 100px over 2 seconds. Use it like __[self showScoreLabelFor:200];__
deanWombourne
That what i was looking for manthanks a ton for ur code snippet.its working.....yippy
shishir.bobby