0

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

Dimitris Bouzikas
  • 4,461
  • 3
  • 25
  • 33
Sasha Shumylo
  • 137
  • 1
  • 8

2 Answers2

1

here is a good example for notification for what you want, i hope that help you: https://github.com/ekurutepe/MPNotificationView or https://github.com/edgurgel/CMNavBarNotificationView or https://github.com/terryworona/TWMessageBarManager

chawki
  • 867
  • 1
  • 8
  • 13
1

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
                                      }];
                 }];
}
sangony
  • 11,636
  • 4
  • 39
  • 55
  • Hi, thnx. But if I want to add a UIButton Play and UIImage? – Sasha Shumylo Feb 23 '14 at 21:43
  • That depends on your overall design idea for your app. The code I posted is just a little animation which moves a UILabel in and out of the visible view. If you want to add buttons and images, I suggest you do that in your main view and not the animated view. If you really wanted to add it to the animated view, you would would have to do a lot more coding than what I posted. – sangony Feb 23 '14 at 21:46
  • I see, then I'll have to animate each object? I mean, there is no way to "group" UILabel, UIButton and UIImage and animate only this "group" ? )) How do you think Apple implemented a banner, that is on the image I posted. I want to create a custom object and call it when I received a notification from GameCenter, wherever I am in app. – Sasha Shumylo Feb 23 '14 at 21:56
  • You can group a bunch of things like UILabel, UIButton, etc... and add them all to a UIView. Then you add the UIView like this [self.view addSubview:myView2]; It sounds like you already have a bunch of great ideas for your app but are little stumped on how to code them. It might be better for you to take a step back and get some more tutorial work under your belt before you proceed or you might end up having countless frustrating hours. I am speaking from experience. – sangony Feb 23 '14 at 22:04
  • Take a look at this site and consider taking some time to do some of their tutorials to take you to the next level. http://www.raywenderlich.com – sangony Feb 23 '14 at 22:05
  • Thank you. I get it. I can draw whatever I need in drawRect: It could look like separate objects (UIImage, UILabel etc), but it's actually one image. I started with Stanford course, but at the end I decided to work on my own project. Only in practice you can understand everything you need. Thanks. – Sasha Shumylo Feb 23 '14 at 22:12