2012-06-28 70 views
2

我有一個方法,如果視頻上傳到Facebook失敗,會被調用。如果該方法被調用,那麼我希望UILabel可以簡短地出現在上傳失敗時用戶碰巧處於的任何視圖控制器中。從一個方法在任何視圖控制器上創建UILabel

這可能嗎?

我之前問過類似的問題關於UIAlertView,但我意識到在某些情況下警報可能會對用戶體驗產生負面影響。

回答

0

你可以做到這一點是許多方面 -

1)您可以添加UILabel到您的應用程序主要Window。 2)如果您使用的是UINavigationController,那麼您將獲得當前viewcontroller的實例,然後可以將UILabel添加到其視圖。

3)如果要在這種情況下使用UITabBarController還可以通過訪問tabBarController的獲取當前viewcontroller實例選定viewcontroller.

0

這個代碼下面林張貼是從來自Facebook HackBook示例應用程序。他們完成類似於你想要的。

- (void)showMessage:(NSString *)message { 
CGRect labelFrame = messageView.frame; 
labelFrame.origin.y = [UIScreen mainScreen].bounds.size.height - self.navigationController.navigationBar.frame.size.height - 20; 
messageView.frame = labelFrame; 
messageLabel.text = message; 
messageView.hidden = NO; 

// Use animation to show the message from the bottom then 
// hide it. 
[UIView animateWithDuration:0.5 
         delay:1.0 
        options: UIViewAnimationCurveEaseOut 
       animations:^{ 
        CGRect labelFrame = messageView.frame; 
        labelFrame.origin.y -= labelFrame.size.height; 
        messageView.frame = labelFrame; 
       } 
       completion:^(BOOL finished){ 
        if (finished) { 
         [UIView animateWithDuration:0.5 
               delay:3.0 
              options: UIViewAnimationCurveEaseOut 
              animations:^{ 
               CGRect labelFrame = messageView.frame; 
               labelFrame.origin.y += messageView.frame.size.height; 
              // UIView *messageView; declared in header 
               messageView.frame = labelFrame; 
              } 
              completion:^(BOOL finished){ 
               if (finished) { 
                messageView.hidden = YES; 
                messageLabel.text = @""; 
               } 
              }]; 
        } 
       }]; 
} 
相關問題