2014-07-02 47 views
0

我有一個視圖,並且我想在視圖導航到時開始動畫。我試圖在ViewWillAppear中做到這一點,但沒有任何反應,我試圖給動畫添加一個延遲,但沒有任何反應。我想在ViewDidAppear這樣做的,但它不叫......動畫無法在ViewWillAppear

這裏是我的代碼:

public override void ViewWillAppear (bool animated) 
      {    
       if(ViewModel.ShouldOpenNotifications) 
       { 
        OpenNotificationsSidebar(); 
        ViewModel.ShouldOpenNotifications = false; 
       } 
       base.ViewWillAppear (animated); 

      } 

void OpenNotificationsSidebar() 
     { 
      NotificationsView.Hidden = false; 
      UIView.Animate (0.5, 1, UIViewAnimationOptions.CurveEaseOut,() => 
       { 
        NotificationsView.Frame = new RectangleF (40, NotificationsView.Frame.Y, NotificationsView.Frame.Width, NotificationsView.Frame.Height); 
        MainTable.Frame = new RectangleF (-280, MainTable.Frame.Y, MainTable.Frame.Width, MainTable.Frame.Height); 
        MainTabBar.Frame = new RectangleF (-280, MainTabBar.Frame.Y, MainTabBar.Frame.Width, MainTabBar.Frame.Height); 
        SettingsView.Frame = new RectangleF (-280, SettingsView.Frame.Y, MainTabBar.Frame.Width, MainTabBar.Frame.Height); 
        MainTable.UserInteractionEnabled = false; 
        MainTabBar.UserInteractionEnabled = false; 
       }, null); 
      _isNotificationsOpen = true; 
      SettingsSwipeView.Hidden = true; 
      UIApplication.SharedApplication.ApplicationIconBadgeNumber = 0; 
     } 

我怎樣才能使這項工作?

感謝

UPDATE

我使用MvvmCross,只是發現ViewDidAppearCalled事件所以現在我正在ViewDidAppearMethod火,但仍然動畫不能正常工作。即使我的延遲設置爲10秒......在動畫中被調用和性質發生改變,但沒有顯示在屏幕上......

UPDATE2 目前唯一可行的就是以下幾點:

Task.Run(()=> 
{ 
    Thread.Sleep(2500); 
    RunDelegateInUiThread(()=> 
     { 
     OpenNotificationsSidebar(); 
     }); 
}); 
+0

我不知道C#,但我敢肯定調用'base.viewWillAppear(動畫)'你的方法到底是一個錯誤。調用super方法應始終是方法中的第一個調用。嘗試在你的方法的開始。你也可以在你的'ViewDidAppear'方法中做同樣的事情。 – michaelsnowden

+0

@doctordoder我已將其移動。它是在開始。仍然沒有去。 –

+0

請使用您的ViewDidAppear代碼 – michaelsnowden

回答

0

把它放在viewDidAppear

+0

問題是ViewDidAppear沒有被調用......它似乎只在我向後導航時被調用。 –

+0

@Amit,他的意思是,讓視圖中的'v'小寫。 –

+0

這是一個UIViewController子類嗎? – believesInSanta

0

我不知道這是否與線程處於活動狀態時的某種延遲有關。這已經發生在我身上了很多,因爲iOS的7.嘗試:

dispatch_async(dispatch_get_main_queue(), ^{ 
    // your code that calls the view. i.e.: 
    YourViewController* YourViewControllerObj = [[YourViewController alloc] 
             initWithNibName:@"YourViewController" 
             bundle:[NSBundle mainBundle]]; 
    // ... more code. 
]); 
+0

你的意思是在ViewDidAppear裏面? –

+0

ViewDidAppear是您的視圖控制器的一部分。我的意思是在你調用視圖控制器之前。我編輯了我的評論以反映這個例子。 – JMerinoH