From 1d129a9989d517ef3fe74566dca057a286df48c4 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Thu, 25 Sep 2014 15:58:58 +0530 Subject: [PATCH 1/4] Conversion of Constraint file from objective c to c# --- .../AnimationFrame.cs | 1 + .../ConstraintsAnimation.cs | 42 +++++++++++++++++++ .../Screenmedia.IFTTT.JazzHands.csproj | 2 + 3 files changed, 45 insertions(+) create mode 100644 JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs 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/ConstraintsAnimation.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs new file mode 100644 index 0000000..b922440 --- /dev/null +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs @@ -0,0 +1,42 @@ +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.AddConstraint (viewConstraint); + + View.Frame = animationFrame.Frame; + + View.SetNeedsLayout (); + } + + 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 From 1fe61fcaac6331b0e9294468547209eb2cdc71e6 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Thu, 25 Sep 2014 19:04:51 +0530 Subject: [PATCH 2/4] Committing implementation of constraint animation --- .../AnimationKeyFrame.cs | 1 + .../ConstraintsAnimation.cs | 2 +- .../JHViewController.cs | 39 ++++++++++++++++++- 3 files changed, 40 insertions(+), 2 deletions(-) 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 index b922440..949bf3b 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs @@ -25,7 +25,7 @@ public override void Animate(int time) View.Frame = animationFrame.Frame; - View.SetNeedsLayout (); + View.LayoutIfNeeded (); } public override AnimationFrame FrameForTime(int time, diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs index 5991c23..2d400ed 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,11 @@ private void PlaceViews () UILabel fourthPageText = AddLabel ("Optimized for scrolling intros", true, 4, 0); ScrollView.AddSubview(fourthPageText); + InputText = AddTextField ("Animation Test", true, 5, 0); + + ScrollView.Add (InputText); + + LastLabel = fourthPageText; } @@ -96,6 +103,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 +267,20 @@ 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(5), + constraintConstant=50.0f, + Frame=InputText.Frame + }); + + + Animator.AddAnimation(textFieldConstraintAnimation); } From ebc8d6f34aab4571043397942da28b8448b2f6c2 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Thu, 25 Sep 2014 21:33:01 +0530 Subject: [PATCH 3/4] Did some changes in applying constraints- its no finished yet. --- .../ConstraintsAnimation.cs | 13 +++++++++---- .../JHViewController.cs | 16 ++++++++++++++-- 2 files changed, 23 insertions(+), 6 deletions(-) diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs index 949bf3b..1fa1aef 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs @@ -17,13 +17,18 @@ public override void Animate(int time) AnimationFrame animationFrame = AnimationFrameForTime(time); - NSLayoutConstraint viewConstraint = new NSLayoutConstraint (); +// NSLayoutConstraint viewConstraint = new NSLayoutConstraint (); +// viewConstraint.Constant=animationFrame.constraintConstant; - viewConstraint.Constant=animationFrame.constraintConstant; + View.Frame = animationFrame.Frame; - View.AddConstraint (viewConstraint); + View.TranslatesAutoresizingMaskIntoConstraints = false; - View.Frame = animationFrame.Frame; + var textFieldTopConstraint = NSLayoutConstraint.Create (View, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, null, NSLayoutAttribute.Top, 1.0f, animationFrame.constraintConstant); + var textFieldBottomConstraint = NSLayoutConstraint.Create (View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, null, NSLayoutAttribute.Bottom, 1.0f, 0f); + View.AddConstraints (new NSLayoutConstraint[] {textFieldTopConstraint, textFieldBottomConstraint }); + + //View.AddConstraint (viewConstraint); View.LayoutIfNeeded (); } diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs index 2d400ed..e5fe204 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs @@ -76,8 +76,16 @@ private void PlaceViews () InputText = AddTextField ("Animation Test", true, 5, 0); + //InputText.TranslatesAutoresizingMaskIntoConstraints = false; + ScrollView.Add (InputText); + var txtTopConstraint = NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, null, NSLayoutAttribute.Top, 1.0f, -20.0f); + var txtBottomConstraint = NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, null, NSLayoutAttribute.Bottom, 1.0f, 0f); + View.AddConstraints (new NSLayoutConstraint[] {txtTopConstraint, txtBottomConstraint }); + + View.LayoutIfNeeded (); + LastLabel = fourthPageText; } @@ -272,11 +280,15 @@ private void ConfigureAnimation() ConstraintsAnimation textFieldConstraintAnimation = new ConstraintsAnimation (this.InputText); + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () + { + Time = TimeForPage(4.35f), + constraintConstant=-20.0f + }); textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () { Time = TimeForPage(5), - constraintConstant=50.0f, - Frame=InputText.Frame + constraintConstant=50.0f }); From 8b9998601d181767128541fbcffad7ed90fa7ec2 Mon Sep 17 00:00:00 2001 From: Manoj Kumar Date: Fri, 26 Sep 2014 20:44:11 +0530 Subject: [PATCH 4/4] Constraint Animation of textfield is working when moving forward. --- .../ConstraintsAnimation.cs | 12 ++++---- .../JHViewController.cs | 28 ++++++++++++++----- 2 files changed, 27 insertions(+), 13 deletions(-) diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs index 1fa1aef..c873989 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHands/ConstraintsAnimation.cs @@ -20,17 +20,17 @@ public override void Animate(int time) // NSLayoutConstraint viewConstraint = new NSLayoutConstraint (); // viewConstraint.Constant=animationFrame.constraintConstant; - View.Frame = animationFrame.Frame; - View.TranslatesAutoresizingMaskIntoConstraints = false; - var textFieldTopConstraint = NSLayoutConstraint.Create (View, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, null, NSLayoutAttribute.Top, 1.0f, animationFrame.constraintConstant); - var textFieldBottomConstraint = NSLayoutConstraint.Create (View, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, null, NSLayoutAttribute.Bottom, 1.0f, 0f); - View.AddConstraints (new NSLayoutConstraint[] {textFieldTopConstraint, textFieldBottomConstraint }); + View.Frame = animationFrame.Frame; - //View.AddConstraint (viewConstraint); + 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, diff --git a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs index e5fe204..57f236c 100644 --- a/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs +++ b/JazzHandsCSharp/Screenmedia.IFTTT.JazzHandsDemo/JHViewController.cs @@ -78,15 +78,21 @@ private void PlaceViews () //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); - var txtTopConstraint = NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Top, NSLayoutRelation.GreaterThanOrEqual, null, NSLayoutAttribute.Top, 1.0f, -20.0f); - var txtBottomConstraint = NSLayoutConstraint.Create (InputText, NSLayoutAttribute.Bottom, NSLayoutRelation.Equal, null, NSLayoutAttribute.Bottom, 1.0f, 0f); - View.AddConstraints (new NSLayoutConstraint[] {txtTopConstraint, txtBottomConstraint }); + 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; } @@ -282,16 +288,24 @@ private void ConfigureAnimation() textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () { - Time = TimeForPage(4.35f), - constraintConstant=-20.0f + Time = TimeForPage(4), + constraintConstant=180 }); + + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () + { + Time = TimeForPage(4.50f), + constraintConstant=200 + }); + textFieldConstraintAnimation.AddKeyFrame (new AnimationKeyFrame () { Time = TimeForPage(5), - constraintConstant=50.0f + constraintConstant=80 }); + Animator.AddAnimation(textFieldConstraintAnimation); }