2014-02-23 169 views
0

我想創建一個回合制匹配。玩家收到通知時player:receivedTurnEventForMatch:didBecomeActive:從屏幕頂部顯示橫幅

我想要顯示從屏幕頂部滑動的橫幅。 「輪到你玩」,類似於Game Center在玩家身份驗證時顯示的橫幅。

我該怎麼辦?應該是UIViewController還是UIAlert,還是什麼? enter image description here

回答

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 
             }]; 
       }]; 
} 
+0

嗨,thnx。但是,如果我想添加一個UIButton播放和UIImage? –

+0

這取決於您的應用程序的整體設計理念。我發佈的代碼只是一個將UILabel移入和移出可見視圖的小動畫。如果你想添加按鈕和圖像,我建議你在主視圖中進行,而不是動畫視圖。如果你真的想把它添加到動畫視圖中,你將不得不做比我發佈的更多的代碼。 – sangony

+0

我明白了,那麼我必須爲每個對象設置動畫效果?我的意思是,沒有辦法對UILabel,UIButton和UIImage進行「分組」,並僅對此「組」進行動畫製作? )) 您如何看待蘋果公司實施的橫幅,這是我張貼的圖像。 我想創建一個自定義對象,並在我收到來自GameCenter的通知時進行調用,無論我身處何處。 –