我想创建一个回合制的比赛。当玩家收到通知player:receivedTurnEventForMatch:didBecomeActive:
我想显示一个从屏幕顶部滑动的横幅。 “轮到你了。玩”类似于游戏中心在玩家身份验证时显示的横幅。
我该怎么办?它应该是UIViewController
还是UIAlert
,还是什么?
答案 0 :(得分:1)
这里有一个很好的例子来通知你想要什么,我希望能帮到你: https://github.com/ekurutepe/MPNotificationView 要么 https://github.com/edgurgel/CMNavBarNotificationView 要么 https://github.com/terryworona/TWMessageBarManager
答案 1 :(得分:1)
有很多方法可以做你提到的事情。这只是其中之一。随意更改代码并阅读UIView动画,您可以自己尝试不同的东西。
-(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
}];
}];
}