Created
February 16, 2017 16:05
-
-
Save softlion/b51578240b7d28db58caff4a09dea7d0 to your computer and use it in GitHub Desktop.
Mvvmcross Rotate180TargetBinding
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/// <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