1

我想我的應用程序的遊戲,在顯示應用程序內的橫幅通知不是我當前UIAlertView的UIApplication didReceiveRemoteNotification,顯示應用程序內的橫幅

- (void)application:(UIApplication *)application didReceiveRemoteNotification:(NSDictionary *)userInfo 
{  
    if (application.applicationState == UIApplicationStateActive) 
    { 
     // Show Alert -> 
     // UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:NSLocalizedString(@"Did receive a Remote Notification", nil) 
     // message:[apsInfo objectForKey:@"alert"] 
     // delegate:self 
     // cancelButtonTitle:NSLocalizedString(@"OK", nil) 
     // otherButtonTitles:nil]; 
     // [alertView show]; 
     // [alertView release]; 

     // Show Banner Notification 
    } 
} 

這裏是我想達到什麼樣的一個例子:

http://i.stack.imgur.com/bFnmj.jpg

我將如何實現我的應用程序的比賽中應用程序內的橫幅通知玩?

+0

你有什麼嘗試?一個'UIView'多線'UILabel'是我的建議 – klcjr89

+0

可能的重複[如何顯示遠程推送通知作爲橫幅樣式在應用程序的活動狀態?](http://stackoverflow.com/questions/13601533/如何顯示遠程推送通知作爲橫幅風格在活動狀態的應用程序) – klcjr89

+0

謝謝。 troop231。這對我很好。 – Lasigal

回答

2
#define BANNER_HEIGHT 66.0  

    if (!showingNotification) { 
     showingNotification = YES; 

     // retrieve message from your actual notification here 
     NSString *message = @"Showing notification"; 

     UIToolbar *newmessageBannerView = [[UIToolbar alloc] initWithFrame:CGRectMake(0, -BANNER_HEIGHT, self.view.frame.size.width, BANNER_HEIGHT)]; 
     newmessageBannerView.translucent = YES; 

     newmessageBannerView.barStyle = UIBarStyleBlack; 
     newmessageBannerView.backgroundColor = [UIColor blackColor]; 

     UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10.0, 33.0, 16.0, 16.0)]; 
     imageView.image = [UIImage imageNamed:@"icon_72"]; 
     [newmessageBannerView addSubview:imageView]; 
     [self.view addSubview:newmessageBannerView]; 

     UILabel *bannerLabel = [[UILabel alloc] initWithFrame:CGRectMake(40.0, 30.0, 320.0, 22.0)]; 
     bannerLabel.textAlignment = NSTextAlignmentLeft; 
     bannerLabel.textColor = [UIColor whiteColor]; 
     bannerLabel.font = [UIFont systemFontOfSize:17.0]; 
     bannerLabel.text = message; 
     bannerLabel.backgroundColor = [UIColor colorWithRed:0.0 green:0.0 blue:0.0 alpha:0.0]; 
     bannerLabel.adjustsFontSizeToFitWidth = YES; 
     [newmessageBannerView addSubview:bannerLabel]; 

     [UIView animateWithDuration:0.25 delay:0.1 options:UIViewAnimationOptionCurveLinear 
         animations:^{ 
          newmessageBannerView.frame = CGRectMake(0, 0, self.view.frame.size.width, BANNER_HEIGHT); 
         } 
         completion:^(BOOL finished) { 
          [UIView animateWithDuration:0.25 delay:2.0 options:UIViewAnimationOptionCurveLinear 
               animations:^{ 
                newmessageBannerView.frame = CGRectMake(0, -BANNER_HEIGHT, self.view.frame.size.width, BANNER_HEIGHT); 
               }completion:^(BOOL finished) { 
                [newmessageBannerView removeFromSuperview]; 
                showingNotification = NO; 
               }]; 
         }]; 
    } 
} 

我試試iOS 6.0,7.04,7.1。

相關問題