简体   繁体   中英

How to Move Button from Right to Left in Xamarin(iOS)

I am New to Xamarin and iOS. I am making App in Visual Studio with Xamarin. I want to move my Button from Right Side to left Side. for that I have use below code :

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

My button is moving but it get back to my Previous Position. Any Help be Appreciated.

This is my Image :

在此处输入图片说明

UpDate :

When I try different code it work better

Change Code :

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

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

           }
           );

Normal Screen :

在此处输入图片说明

when Click on button :

在此处输入图片说明

But it have some issue The Button is go some height upper side..

Ohh It was silly mistake why it goes upper side :

I change the code to this way.

Instead of my point

CGPoint(50,611);

to

CGPoint(50, fabButton.Center.Y);

because i want move my button to X direction then why I want to change the Y direction value.

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

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

           }
           );

Normal Screen :

在此处输入图片说明

After Button Click :

在此处输入图片说明

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM