2016-09-20 124 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

相关问题