动画在ViewWillAppear中无效

时间:2014-07-02 18:41:50

标签: ios animation xamarin.ios xamarin mvvmcross

我有一个视图,我希望在导航到视图后启动动画。我试图在ViewWillAppear中做到但没有任何反应,我试图给动画添加一个延迟,但没有任何反应。我想在ViewDidAppear中这样做,但它没有被调用......

这是我的代码:

    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;
        }

我该如何做到这一点?

由于

更新

我正在使用MvvmCross并且刚刚找到了ViewDidAppearCalled事件,所以现在我要触发ViewDidAppearMethod,但动画仍无效。甚至如果我将延迟设置为10秒......动画确实被调用并且属性被更改但屏幕上没有显示...

UPDATE2 目前唯一有效的是:

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

3 个答案:

答案 0 :(得分:1)

将其放在viewDidAppear中。

答案 1 :(得分: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.
]);

答案 2 :(得分:0)

为什么viewDidAppear的原因以及为什么不需要延迟等:在viewWillAppear中不满足Autolayout约束。在viewWillAppear viewWillLayout和DidLayoutSubviews被调用以满足约束。在调用此viewDidAppear之后。所有约束都得到了很好的休息。然后你应该执行动画。