Permalink
Browse files

Fixed stuff up and added more docs!

Request more documentation and you shall receive!
  • Loading branch information...
1 parent 991f78d commit dbc280a046c24a2f540e29ef37c48629158f7602 @avaidyam avaidyam committed Jul 20, 2012
Showing with 20 additions and 4 deletions.
  1. +18 −1 lib/UIKit/TUILayoutConstraint.h
  2. +2 −3 lib/UIKit/TUILayoutConstraint.m
@@ -92,7 +92,24 @@ typedef CGFloat (^TUILayoutTransformer)(CGFloat);
resized or moved, declineButton will be automatically moved to have its right edge
positioned 10 pixels to the left of acceptButton left edge.
This is only a simple example, a more complex example could use block transformers
- and a fabs(sin()) to constrict a tranformation to a |sin(x)| curve. And more!
+ and a fabs(sinf()) to constrict a tranformation to a |sin(x)| curve, like below.
+
+ ```
+ TUIButton *helpButton = [TUIButton buttonWithType:TUIButtonTypeCustom];
+ [self setUpButton:helpButton];
+ [helpButton setLayoutName:@"help"];
+
+ [helpButton addConstraint:[TUILayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeMinY
+ relativeTo:@"accept"
+ attribute:CHLayoutConstraintAttributeMinY
+ blockTransformer:^(CGFloat source) {
+ return fabs((50 * sinf(source))) + 20;
+ ]];
+
+ [helpButton addConstraint:[TUILayoutConstraint constraintWithAttribute:CHLayoutConstraintAttributeCenter
+ relativeTo:@"superview"
+ attribute:CHLayoutConstraintAttributeFrame]];
+ ```
Along with simple scale and offset constraints, you can specify a block
value transformer to use more complex transformations. You can also bind
@@ -47,14 +47,14 @@ @implementation TUILayoutConstraint
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
relativeTo:(NSString *)srcLayer
attribute:(TUILayoutConstraintAttribute)srcAttr {
- return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0 offset:0.0];
+ return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0f offset:0.0f];
}
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
relativeTo:(NSString *)srcLayer
attribute:(TUILayoutConstraintAttribute)srcAttr
offset:(CGFloat)offset {
- return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0 offset:offset];
+ return [self constraintWithAttribute:attr relativeTo:srcLayer attribute:srcAttr scale:1.0f offset:offset];
}
+ (id)constraintWithAttribute:(TUILayoutConstraintAttribute)attr
@@ -90,7 +90,6 @@ - (id)initWithAttribute:(TUILayoutConstraintAttribute)attr
double sourceAttributeRange = floor(log10(srcAttr));
NSAssert(fabs(attributeRange - sourceAttributeRange) < 0.001, @"Invalid source and target attributes: %f, %f.", sourceAttributeRange, attributeRange);
- NSAssert(scale > 0.0f && offset > 0.0f, @"Invalid scale and offset: %f, %f", scale, offset);
if((self = [super init])) {
_attribute = attr;

0 comments on commit dbc280a

Please sign in to comment.