Mailing Lists: Apple Mailing Lists

Image of Mac OS face in stamp
 
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Using constraints on a Layer




Not sure if I'm reading and understanding the documentation correctly.
It's my understanding that I could use constraints on a layer B, such that it could "track" the size and position of another layer (for example).


As an example assuming I have a layer (it will be a sibling) that I want to track called 'clickedLayer', I might do this:

- (void) selectLayer:(CALayer*)clickedLayer {
currentSelectedThing.frame = clickedLayer.frame;
NSMutableArray *constraints = [NSMutableArray array];

currentSelectedThing.borderWidth = 30;
currentSelectedThing.borderColor = CGColorGetConstantColor(kCGColorWhite);
currentSelectedThing.opacity = 1.0;
currentSelectedThing.zPosition = 1;


[constraints addObject:[CAConstraint constraintWithAttribute:kCAConstraintMidX relativeTo:clickedLayer.name attribute:kCAConstraintMidX]];
[constraints addObject:[CAConstraint constraintWithAttribute:kCAConstraintMidY relativeTo:clickedLayer.name attribute:kCAConstraintMidY]];
[constraints addObject:[CAConstraint constraintWithAttribute:kCAConstraintWidth relativeTo:clickedLayer.name attribute:kCAConstraintWidth]];
[constraints addObject:[CAConstraint constraintWithAttribute:kCAConstraintHeight relativeTo:clickedLayer.name attribute:kCAConstraintHeight]];
currentSelectedThing.constraints = constraints;


	self.selectedLayer = clickedLayer;
}


This currentSelectedThing layer has been previously added to the root layer by:


	self.currentSelectedThing = [CALayer layer];
	currentSelectedThing.opacity = 0;
	currentSelectedThing.bounds = CGRectZero;
	currentSelectedThing.name = @"currentSelection";
	currentSelectedThing.needsDisplayOnBoundsChange = YES;
	[self.layer addSublayer:currentSelectedThing];

The part I don't understand is that I cannot get this to work unless I set the frame on the layer. It just doesn't show up.
currentSelectedThing.frame = clickedLayer.frame;


If I don't set the frame it never shows (presumably it's not getting resized). Is my understanding of constraints incorrect here? Or must I do something else in order have the constraint apply?

--
Regards,
Neil Clayton,  http://shinywhitebox.com







_______________________________________________
Do not post admin requests to the list. They will be ignored.
Quartz-dev mailing list      (email@hidden)
Help/Unsubscribe/Update your Subscription:
http://lists.apple.com/mailman/options/quartz-dev/email@hidden

This email sent to email@hidden


Visit the Apple Store online or at retail locations.
1-800-MY-APPLE

Contact Apple | Terms of Use | Privacy Policy

Copyright © 2007 Apple Inc. All rights reserved.