Created
March 18, 2013 22:37
-
-
Save blitzvb/5191480 to your computer and use it in GitHub Desktop.
Easy AutoLayout help from Frank
This file contains hidden or 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
My View Controller : | |
using System; | |
using System.Drawing; | |
using MonoTouch.Foundation; | |
using MonoTouch.UIKit; | |
using Async.iOS; | |
namespace FrankAutoLayout | |
{ | |
public partial class FrankAutoLayoutViewController : UIViewController | |
{ | |
int ButtonWidth = 100; | |
int VPadding = 20; | |
int HPadding = 20; | |
public FrankAutoLayoutViewController () : base ("FrankAutoLayoutViewController", null) | |
{ | |
} | |
public override void DidReceiveMemoryWarning () | |
{ | |
// Releases the view if it doesn't have a superview. | |
base.DidReceiveMemoryWarning (); | |
// Release any cached data, images, etc that aren't in use. | |
} | |
public override void ViewDidLoad () | |
{ | |
base.ViewDidLoad (); | |
// this.LayoutWithConstraints(); | |
View.BackgroundColor = UIColor.Red; | |
this.LayoutWithEase(); | |
} | |
public override void ViewWillAppear (bool animated) | |
{ | |
base.ViewWillAppear (animated); | |
} | |
void LayoutWithEase () | |
{ | |
View.ConstrainLayout (() => | |
button.Frame.Width == ButtonWidth && | |
button.Frame.Right == View.Frame.Right - HPadding && | |
button.Frame.Top == View.Frame.Top + VPadding && | |
text.Frame.Left == View.Frame.Left + HPadding && | |
text.Frame.Right == button.Frame.Left - HPadding && | |
text.Frame.Top == button.Frame.Top | |
); | |
} | |
void LayoutWithConstraints () | |
{ | |
// Set button width | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
button, NSLayoutAttribute.Width, | |
NSLayoutRelation.Equal, | |
null, NSLayoutAttribute.NoAttribute, | |
0, ButtonWidth)); | |
// Set button top | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
button, NSLayoutAttribute.Top, | |
NSLayoutRelation.Equal, | |
View, NSLayoutAttribute.Top, | |
1, VPadding)); | |
// Set button right | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
button, NSLayoutAttribute.Right, | |
NSLayoutRelation.Equal, | |
View, NSLayoutAttribute.Right, | |
1, -HPadding)); | |
// Set text left | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
text, NSLayoutAttribute.Left, | |
NSLayoutRelation.Equal, | |
View, NSLayoutAttribute.Left, | |
1, HPadding)); | |
// Set text right | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
text, NSLayoutAttribute.Right, | |
NSLayoutRelation.Equal, | |
button, NSLayoutAttribute.Left, | |
1, -HPadding)); | |
// Set text top | |
View.AddConstraint (NSLayoutConstraint.Create ( | |
text, NSLayoutAttribute.Top, | |
NSLayoutRelation.Equal, | |
button, NSLayoutAttribute.Top, | |
1, 0)); | |
} | |
} | |
} | |
Unhandled Exception: | |
System.NotSupportedException: Unknown node type Convert | |
at Async.iOS.Layout.GetRight (System.Linq.Expressions.Expression expr) [0x00196] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:115 | |
at Async.iOS.Layout.CompileConstraint (System.Linq.Expressions.BinaryExpression expr) [0x00067] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:50 | |
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator1B`2[System.Linq.Expressions.BinaryExpression,MonoTouch.UIKit.NSLayoutConstraint].MoveNext () [0x00059] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2269 | |
at System.Linq.Enumerable.ToArray[NSLayoutConstraint] (IEnumerable`1 source) [0x0007c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2899 | |
at Async.iOS.Layout.ConstrainLayout (MonoTouch.UIKit.UIView view, System.Linq.Expressions.Expression`1 constraints) [0x00014] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:27 | |
at FrankAutoLayout.FrankAutoLayoutViewController.LayoutWithEase () [0x00000] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/FrankAutoLayoutViewController.cs:44 | |
at FrankAutoLayout.FrankAutoLayoutViewController.ViewDidLoad () [0x00016] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/FrankAutoLayoutViewController.cs:35 | |
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr) | |
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00012] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:128 | |
at FrankAutoLayout.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00031] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/AppDelegate.cs:33 | |
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) | |
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004d] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 | |
at FrankAutoLayout.Application.Main (System.String[] args) [0x00000] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Main.cs:17 | |
2013-03-18 15:35:22.301 FrankAutoLayout[26413:c07] Unhandled managed exception: Unknown node type Convert (System.NotSupportedException) | |
at Async.iOS.Layout.GetRight (System.Linq.Expressions.Expression expr) [0x00196] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:115 | |
at Async.iOS.Layout.CompileConstraint (System.Linq.Expressions.BinaryExpression expr) [0x00067] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:50 | |
at System.Linq.Enumerable+<CreateSelectIterator>c__Iterator1B`2[System.Linq.Expressions.BinaryExpression,MonoTouch.UIKit.NSLayoutConstraint].MoveNext () [0x00059] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2269 | |
at System.Linq.Enumerable.ToArray[NSLayoutConstraint] (IEnumerable`1 source) [0x0007c] in /Developer/MonoTouch/Source/mono/mcs/class/System.Core/System.Linq/Enumerable.cs:2899 | |
at Async.iOS.Layout.ConstrainLayout (MonoTouch.UIKit.UIView view, System.Linq.Expressions.Expression`1 constraints) [0x00014] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Layout.cs:27 | |
at FrankAutoLayout.FrankAutoLayoutViewController.LayoutWithEase () [0x00000] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/FrankAutoLayoutViewController.cs:44 | |
at FrankAutoLayout.FrankAutoLayoutViewController.ViewDidLoad () [0x00016] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/FrankAutoLayoutViewController.cs:35 | |
at (wrapper managed-to-native) MonoTouch.ObjCRuntime.Messaging:void_objc_msgSend (intptr,intptr) | |
at MonoTouch.UIKit.UIWindow.MakeKeyAndVisible () [0x00012] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIWindow.g.cs:128 | |
at FrankAutoLayout.AppDelegate.FinishedLaunching (MonoTouch.UIKit.UIApplication app, MonoTouch.Foundation.NSDictionary options) [0x00031] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/AppDelegate.cs:33 | |
at (wrapper managed-to-native) MonoTouch.UIKit.UIApplication:UIApplicationMain (int,string[],intptr,intptr) | |
at MonoTouch.UIKit.UIApplication.Main (System.String[] args, System.String principalClassName, System.String delegateClassName) [0x0004d] in /Developer/MonoTouch/Source/monotouch/src/UIKit/UIApplication.cs:38 | |
at FrankAutoLayout.Application.Main (System.String[] args) [0x00000] in /Volumes/Tapstic/Xamarin/Devel/Experiment/FrankAutoLayout/FrankAutoLayout/Main.cs:17 | |
mono-rt: Stacktrace: |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment