Skip to content

Instantly share code, notes, and snippets.

@softlion
Created June 4, 2014 10:06
Show Gist options
  • Save softlion/9ec299924164157ee9a0 to your computer and use it in GitHub Desktop.
Save softlion/9ec299924164157ee9a0 to your computer and use it in GitHub Desktop.
protected static void AddParallaxEffect(UIView back)
{
//var frame = back.Frame;
//back.Superview.RemoveConstraints(back.Superview.Constraints.Where(c => c.FirstItem == back).ToArray());
//back.Frame = frame;
var keypathx = "constraints[0].constant";
var keypathy = "constraints[1].constant";
var xMotionEffect = new UIInterpolatingMotionEffect(keypathx, UIInterpolatingMotionEffectType.TiltAlongHorizontalAxis)
{
MinimumRelativeValue = new NSNumber(-10),
MaximumRelativeValue = new NSNumber(10)
};
var yMotionEffect = new UIInterpolatingMotionEffect(keypathy, UIInterpolatingMotionEffectType.TiltAlongVerticalAxis)
{
MinimumRelativeValue = new NSNumber(-10),
MaximumRelativeValue = new NSNumber(10)
};
back.Superview.AddMotionEffect(new UIMotionEffectGroup {MotionEffects = new[] {xMotionEffect, yMotionEffect}});
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment