1

I am trying to translate this code in my solution to enable a view to gracefully fade when clicked:

[UIView transitionWithView:button
     duration:0.4
     options:UIViewAnimationOptionTransitionCrossDissolve
     animations:NULL
     completion:NULL];

button.hidden = YES;

But I can't find the equivalent of transitionWithView under UIView in Xamarin, can someone advise?

I tried this for a different animation but it does not give the option of dissolving:

UIView.SetAnimationTransition(UIViewAnimationTransition.CurlDown, button, true);
Community
  • 1
  • 1
tallpaul
  • 1,220
  • 2
  • 13
  • 35

2 Answers2

3

Setting the hidden property will just hide the UIView. You can use the following code to animate out your view, and use the callback to execute logic when the animation is done.

UIView.Animate (2, 0, UIViewAnimationOptions.CurveLinear,
    () => {
       button.Alpha = 0.0f;
    },
    () => {
      // animation complete logic 
    }
);

The code above will fade out the button view over 2 second, with a delay of 0 seconds using a linear curve.

Filled Stacks
  • 4,116
  • 1
  • 23
  • 36
1
UIView.Transition(button, 0.4, UIViewAnimationOptions.TransitionCrossDissolve, null,
  () => { 
    button.Hidden = true; 
}); 

UIKit.UIView.Transition

Ref: https://developer.xamarin.com/api/member/UIKit.UIView.Transition/p/UIKit.UIView/System.Double/UIKit.UIViewAnimationOptions/System.Action/System.Action/

SushiHangover
  • 73,120
  • 10
  • 106
  • 165