diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationFrame.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationFrame.cs index 7488c55..f261bbe 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationFrame.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationFrame.cs @@ -13,6 +13,7 @@ public class AnimationFrame public Single Angle; public Transform3D Transform = new Transform3D(); public Single Scale; + public Single constraintConstant; } } diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationKeyFrame.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationKeyFrame.cs index 31c3ba5..2e05589 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationKeyFrame.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/AnimationKeyFrame.cs @@ -260,6 +260,7 @@ public enum AnimationType Angle, Transform, Scale, + constraintConstant } } diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs new file mode 100644 index 0000000..c873989 --- /dev/null +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs @@ -0,0 +1,47 @@ +using System; +using MonoTouch.UIKit; +using System.Linq; +using MonoTouch.CoreGraphics; + +namespace Screenmedia.IFTTT.JazzHands +{ + public class ConstraintsAnimation: Animation + { + public ConstraintsAnimation (UIView view) : base(view) + { + } + public override void Animate(int time) + { + if (KeyFrames.Count() <= 1) + return; + + AnimationFrame animationFrame = AnimationFrameForTime(time); + +// NSLayoutConstraint viewConstraint = new NSLayoutConstraint (); +// viewConstraint.Constant=animationFrame.constraintConstant; + + View.TranslatesAutoresizingMaskIntoConstraints = false; + + View.Frame = animationFrame.Frame; + + View.AddConstraints (new[] { + NSLayoutConstraint.Create (View, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 14), + NSLayoutConstraint.Create (View, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, animationFrame.constraintConstant), + }); + + View.LayoutIfNeeded (); + + } + + public override AnimationFrame FrameForTime(int time, + AnimationKeyFrame startKeyFrame, + AnimationKeyFrame endKeyFrame) + { + AnimationFrame animationFrame = new AnimationFrame (); + animationFrame.constraintConstant = TweenValueForStartTime (startKeyFrame.Time, endKeyFrame.Time, startKeyFrame.constraintConstant, endKeyFrame.constraintConstant, time); + + return animationFrame; + } + } +} + diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/Screenmedia.IFTTT.JazzHands.csproj b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/Screenmedia.IFTTT.JazzHands.csproj index effdddd..47b1dde 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/Screenmedia.IFTTT.JazzHands.csproj +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/Screenmedia.IFTTT.JazzHands.csproj @@ -36,6 +36,7 @@ + @@ -53,6 +54,7 @@ + \ No newline at end of file diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs index 5991c23..57f236c 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs @@ -13,12 +13,14 @@ namespace Screenmedia.IFTTT.JazzHandsDemo { public class JHViewController : AnimatedScrollViewController, IAnimatedScrollViewController { - private const int NumberOfPages = 4; + private const int NumberOfPages = 5; public UIImageView Wordmark { get; set;} public UIImageView Unicorn { get; set;} public UILabel LastLabel { get; set;} public UILabel FirstLabel { get; set;} + public UITextField InputText { get; set;} + public UIButton InputButton { get; set;} public override void DidReceiveMemoryWarning () @@ -72,6 +74,25 @@ private void PlaceViews () UILabel fourthPageText = AddLabel ("Optimized for scrolling intros", true, 4, 0); ScrollView.AddSubview(fourthPageText); + InputText = AddTextField ("Animation Test", true, 5, 0); + + //InputText.TranslatesAutoresizingMaskIntoConstraints = false; + + InputText.AddConstraints (new[] { + NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Height, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 30), + NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Width, NSLayoutRelation.Equal, null, NSLayoutAttribute.NoAttribute, 1, 180), + }); + + + ScrollView.Add (InputText); + + ScrollView.AddConstraints (new[] { + NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Left, NSLayoutRelation.Equal, ScrollView, NSLayoutAttribute.Left, 1, (View.Frame.Size.Width * 4)+50), + NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Top, NSLayoutRelation.Equal, ScrollView, NSLayoutAttribute.Top, 1, 130), + }); + + View.LayoutIfNeeded (); + LastLabel = fourthPageText; } @@ -96,6 +117,22 @@ private UILabel AddLabel(string text, bool IsOffset, int page = 0, float y = 0) return l; } + private UITextField AddTextField(string text, bool IsOffset, int page = 0, float y = 0) + { + var l = new UITextField(); + l.Text = text; + l.SizeToFit(); + l.Center = View.Center; + l.BackgroundColor = UIColor.Gray; + if (IsOffset) + { + var rect = l.Frame; + rect.Offset (new PointF (TimeForPage (page), y)); + l.Frame = rect; + } + return l; + } + private void ConfigureAnimation() { Single dy = 240; @@ -244,6 +281,32 @@ private void ConfigureAnimation() Alpha = 0.0f }); Animator.AddAnimation(labelAlphaAnimation); + + //Constraint Animation on textfield of last page + + ConstraintsAnimation textFieldConstraintAnimation = new ConstraintsAnimation (this.InputText); + + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () + { + Time = TimeForPage(4), + constraintConstant=180 + }); + + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () + { + Time = TimeForPage(4.50f), + constraintConstant=200 + }); + + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () + { + Time = TimeForPage(5), + constraintConstant=80 + }); + + + + Animator.AddAnimation(textFieldConstraintAnimation); }