我想创建一个回合制比赛。当玩家收到通知时player:receivedTurnEventForMatch:didBecomeActive:
我想显示一个从屏幕顶部滑动的横幅。“轮到你了。玩”类似于 Game Center 在玩家通过身份验证时显示的横幅。
我该怎么做?应该是UIViewController
orUIAlert
还是什么?
我想创建一个回合制比赛。当玩家收到通知时player:receivedTurnEventForMatch:didBecomeActive:
我想显示一个从屏幕顶部滑动的横幅。“轮到你了。玩”类似于 Game Center 在玩家通过身份验证时显示的横幅。
我该怎么做?应该是UIViewController
orUIAlert
还是什么?
这是通知您想要的内容的一个很好的例子,我希望对您有所帮助: https ://github.com/ekurutepe/MPNotificationView 或 https://github.com/edgurgel/CMNavBarNotificationView 或 https://github.com/特里沃罗纳/TWMessageBarManager
有很多方法可以做你提到的事情。这只是其中之一。随意更改代码并阅读 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
}];
}];
}