Skip to content

Instantly share code, notes, and snippets.

@softlion
Created February 16, 2017 16:05
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save softlion/b51578240b7d28db58caff4a09dea7d0 to your computer and use it in GitHub Desktop.
Save softlion/b51578240b7d28db58caff4a09dea7d0 to your computer and use it in GitHub Desktop.
Mvvmcross Rotate180TargetBinding
/// <summary>
/// Usage:
/// set.Bind(AnyView).For(Rotate180TargetBinding.Name).To(vm => vm.AnyBooleanValue);
/// </summary>
public class Rotate180TargetBinding : MvxTargetBinding
{
private readonly WeakReference<UIView> weakView;
public const string Name = "Rotate180";
public static void Register(IMvxTargetBindingFactoryRegistry registry)
{
registry.RegisterCustomBindingFactory<UIView>(Name, view => new Rotate180TargetBinding(view));
}
public override Type TargetType => typeof(UIView);
public override MvxBindingMode DefaultMode => MvxBindingMode.OneWay;
public Rotate180TargetBinding(UIView target) : base(target)
{
weakView = new WeakReference<UIView>(target);
}
public override void SetValue(object value)
{
var isOn = value.ConvertToBoolean();
UIView view;
if (!weakView.TryGetTarget(out view))
return;
UIView.Animate(.4, 0, UIViewAnimationOptions.CurveEaseInOut, () =>
{
view.Transform = isOn ? CGAffineTransform.MakeRotation((nfloat)Math.PI-0.01f) : CGAffineTransform.MakeIdentity();
}, null);
}
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment