2016-09-20 104 views
0

我是Xamarin和iOS的新手。我使用Xamarin在Visual Studio中製作應用程序。我想將我的按鈕從右側移動到左側。因爲我使用下面的代碼:如何在Xamarin中將按鈕從右向左移動(iOS)

fabButton.SetImage(UIImage.FromFile("Plus Math-24"), UIControlState.Normal); 

      pt = fabButton.Center; 

      UIView.Animate(2, 0, UIViewAnimationOptions.CurveEaseInOut, 
       () => { 

        fabButton.Center = new CGPoint(UIScreen.MainScreen.Bounds.Left - fabButton.Frame.Width/15, fabButton.Center.Y);}, 
      () => { 
       fabButton.Center = pt;} 
      ); 

我的按鈕正在移動,但它回到我的以前的位置。任何幫助被讚賞。

這是我的圖片:

enter image description here

更新:

當我嘗試不同的代碼更好地工作

更改代碼:

UIView.Animate(2, 0, UIViewAnimationOptions.CurveEaseInOut, 
       () => 
       { 

        fabButton.Center = new CGPoint(50,611); 
       }, 
      () => 
      { 

      } 
      ); 

正常屏幕:

enter image description here

當點擊按鈕:

enter image description here

但它有一些問題,這個按鈕是走一些高度上邊..

回答

0

喔這是愚蠢的錯誤,爲什麼它上邊:

我改變這樣的代碼。

而不是我點的

CGPoint(50,611); 

CGPoint(50, fabButton.Center.Y);

,因爲我想將我的按鈕,X方向,那麼爲什麼我要改變Y方向的值。

UIView.Animate(2, 0, UIViewAnimationOptions.CurveEaseInOut, 
       () => 
       { 

        fabButton.Center = new CGPoint(50,fabButton.Center.Y); 
       }, 
      () => 
      { 

      } 
      ); 

正常屏幕:

enter image description here

後按鈕點擊:

enter image description here

相關問題