Frage

I want to create a turn-based match. When player received a notification player:receivedTurnEventForMatch:didBecomeActive:

I want to show a banner that slides from the top of the screen. "Your turn. Play" similar to the banner that Game Center shows when player is authenticated.

How can I do it? Should it be a UIViewController or UIAlert, or what? enter image description here

War es hilfreich?

Andere Tipps

There are MANY ways to do what you mentioned. This is just one of them. Feel free to change the code around and read up on UIView animations to you can try out different things yourself.

-(void)myMethod {
// create UILabel and set its properties
UILabel *myLabel = [[UILabel alloc] initWithFrame:CGRectMake(0, 20, 320, 50)];
myLabel.backgroundColor = [UIColor grayColor];
NSString *myLabelText = @"Welcome back, Mike Lyman"; // showing you to use NSString for label text
myLabel.textAlignment = NSTextAlignmentCenter;
myLabel.text = myLabelText;

[self.view addSubview:myLabel]; // add UILabel to view

myLabel.frame = CGRectMake(0, -50, 320, 50); // set text label frame offscreen

// start the animation to slide UILabel into visible view
[UIView animateWithDuration:0.5 delay:0
                    options:UIViewAnimationOptionCurveLinear
                 animations:^ {
                     myLabel.frame = CGRectMake(0, 20, 320, 50);

                 }
                 completion:^(BOOL finished) {
                     // after 1 second delay, start sliding UILabel out of visible view
                     [UIView animateWithDuration:0.5 delay:1
                                         options:UIViewAnimationOptionCurveLinear
                                      animations:^ {
                                          myLabel.frame = CGRectMake(0, -50, 320, 50);

                                      }
                                      completion:^(BOOL finished) {
                                          NSLog(@"Done");
                                          [self.view removeFromSuperview]; // remove UILabel from view completely
                                      }];
                 }];
}
Lizenziert unter: CC-BY-SA mit Zuschreibung
Nicht verbunden mit StackOverflow
scroll top