I have a simple Mac app that I am developing. I want to be able to apply a transform on a NSButton and make it bigger. Twice its size. However my code is not working, it just slides the button to a corner. Does anyone know what is wrong?
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
[numberButton1.animator.layer setAffineTransform:CGAffineTransformMakeScale(4.0, 4.0)];
numberButton1.layer.anchorPoint = CGPointMake(0.5, 0.5);
[numberButton1.animator.layer setAffineTransform:CGAffineTransformMakeScale(1.0, 1.0)];
} completionHandler:nil];
Update 1
I tried the following, but it doesn't do anything :(
CGAffineTransform test = CGAffineTransformMakeScale(4.0, 4.0);
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx) {
numberButton1.animator.layer.affineTransform = test;
} completionHandler:^{
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *ctx) {
numberButton1.animator.layer.affineTransform = CGAffineTransformIdentity;
} completionHandler:^{
NSLog(@"Done...");
}];
}];
Update 2
Here is my code sudo, hopefully this will help:
My header (.h) file:
#import <Cocoa/Cocoa.h>
#import <QuartzCore/QuartzCore.h>
@interface ViewController : NSViewController {
IBOutlet NSButton *numberButton1;
}
-(IBAction)demo:(id)sender;
@end
And my implementation (.m) file:
#import "ViewController.h"
@implementation ViewController
-(IBAction)demo:(id)sender {
CGRect frame = numberButton1.layer.frame;
CGPoint center = CGPointMake(CGRectGetMidX(frame), CGRectGetMidY(frame));
numberButton1.layer.position = center;
numberButton1.layer.anchorPoint = CGPointMake(0.5, 0.5);
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.allowsImplicitAnimation = YES;
[[NSAnimationContext currentContext] setDuration:0.2];
numberButton1.animator.layer.affineTransform = CGAffineTransformMakeScale(4.0, 4.0);
} completionHandler:^{
[NSAnimationContext runAnimationGroup:^(NSAnimationContext *context) {
context.allowsImplicitAnimation = YES;
[[NSAnimationContext currentContext] setDuration:0.2];
numberButton1.animator.layer.affineTransform = CGAffineTransformIdentity;
} completionHandler:nil];
}];
}
- (void)viewDidLoad {
[super viewDidLoad];
// Do any additional setup after loading the view.
numberButton1.wantsLayer = YES;
numberButton1.layerContentsRedrawPolicy = NSViewLayerContentsRedrawOnSetNeedsDisplay;
numberButton1.layer.backgroundColor = [NSColor colorWithRed:(17/255.0) green:(145/255.0) blue:(44/255.0) alpha:1.0].CGColor;
}
- (void)setRepresentedObject:(id)representedObject {
[super setRepresentedObject:representedObject];
// Update the view, if already loaded.
}
@end
I am also not using Auto Layout
for my UI files.
Thanks, Dan.