How did the author create those shapes and how can I do this in OS X?
NSTextField does have a background colour. So you could drag Wrapping Labels onto your window instead and just delete the text in the title.
- (void)viewDidLoad
{
[super viewDidLoad];
[self createPhysicsWorld];
for (UIView *oneView in self.view.subviews)
{
[self addPhysicalBodyForView:oneView];
}
tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(tick:) userInfo:nil repeats:YES];
}
So for the viewdidLoad: iOS method I create a NSViewController and call
-(void)awakeFromNib: and in that awakeFromNib: method I can use the same iOS code that is in the viewDidLoad? Do I create a different NSView subclass for each of the colored squares and in their awakeFromNib: method I call addPhysicalBodyForView: ?
I know about the background color, but how exactly do I handle the views I create? I have no idea how to convert this code:
Code:- (void)viewDidLoad { [super viewDidLoad]; [self createPhysicsWorld]; for (UIView *oneView in self.view.subviews) { [self addPhysicalBodyForView:oneView]; } tickTimer = [NSTimer scheduledTimerWithTimeInterval:1.0/60.0 target:self selector:@selector(tick:) userInfo:nil repeats:YES]; }
-(void)awakeFromNib{
[self createPhysicsWorld];
NSView *contentView;
contentView = [window contentView];
for (NSView * oneView in [contentView subviews]){
[self addPhysicalBodyForView:oneView];
}
}
physicalView.tag = (int)body;
Code:physicalView.tag = (int)body;
I am not exactly sure what guarding a call is.You'll then need to guard the call to addPhysicalBodyForView: in awakeFromNib: so it only happens with subviews that are kinds of NSControl.
Okay, Thanks!
I did everything but this:
I am not exactly sure what guarding a call is.
I'm still not quite sure what you mean.
Thanks
for (NSView * oneView in [contentView subviews]){
[COLOR=blue]if ([oneView isKindOf:@class(NSControl)]) {[/COLOR]
[self addPhysicalBodyForView:[COLOR=blue](NSControl*)[/COLOR]oneView];
[COLOR=blue]}[/COLOR]
}
if ([oneView isKindOfClass:[NSControl class]]) {
[self addPhysicalBodyForView:(NSControl*)oneView];
}
The code you provided didn't compile and gave the following error:
"Unexpected @ in program"
I changed the code to this:
Is the code I created correct?Code:if ([oneView isKindOfClass:[NSControl class]]) { [self addPhysicalBodyForView:(NSControl*)oneView]; }
CGAffineTransform transform = CGAffineTransformMakeRotation(- b->GetAngle());
oneView.transform = transform
I actually do have another question,
I will be applying a CGAffineTransform to a view (same tutorial) and the author is using an iOS only property. What is an equivalent way to do this in OS X?Code:CGAffineTransform transform = CGAffineTransformMakeRotation(- b->GetAngle()); oneView.transform = transform
I actually didn't find a method or property that is the equivalent to the iOS property.
I can't find anything there about CGAffineTransforms on NSViews.![]()
CGAffineTransform transform = CGAffineTransformMakeRotation(- b->GetAngle());
oneView.wantsLayer = YES;
[oneView.layer setAffineTransform:transform];