/* * AppController.j * Animator * * Created by You on March 27, 2020. * Copyright 2020, Your Company All rights reserved. */ @import @import @implementation AppController : CPObject { @outlet CPWindow theWindow; CPView containerView; CPView viewA; CPView viewB; CPButton switchButton; int currentView; } - (void)applicationDidFinishLaunching:(CPNotification)aNotification { // This is called when the application is done loading. } - (void)awakeFromCib { // This is called when the cib is done loading. // You can implement this method on any object instantiated from a Cib. // It's a useful hook for setting up current UI values, and other things. // In this case, we want the window from Cib to become our full browser window [theWindow setFullPlatformWindow:YES]; containerView = [[CPView alloc] initWithFrame:CGRectMake(10, 10, 200, 100)]; viewA = [[CPView alloc] initWithFrame:CGRectMake(0, 0, 200, 100)]; viewB = [[CPView alloc] initWithFrame:CGRectMake(200, 0, 200, 100)]; [containerView setBackgroundColor:[CPColor whiteColor]]; [viewA setBackgroundColor:[CPColor redColor]]; [viewB setBackgroundColor:[CPColor blueColor]]; currentView = 0; // means viewA while 1 means viewB switchButton = [CPButton buttonWithTitle:@"Switch views"]; [switchButton setFrameOrigin:CGPointMake(10 + (200 - [switchButton frameSize].width)/2, 116)]; [switchButton setTarget:self]; [switchButton setAction:@selector(switchViews:)]; [[theWindow contentView] addSubview:containerView]; [[theWindow contentView] addSubview:switchButton]; [containerView addSubview:viewA]; [containerView addSubview:viewB]; } - (IBAction)switchViews:(id)sender { [CPAnimationContext beginGrouping]; var context = [CPAnimationContext currentContext]; [context setDuration:1.00]; [context setTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut]]; // [context setCompletionHandler:function() // { // [self finishStopTracking]; // }]; if (currentView == 0) { [[viewA animator] setFrameOrigin:CGPointMake(-201,0)]; [[viewB animator] setFrameOrigin:CGPointMake(0,0)]; } else { [[viewA animator] setFrameOrigin:CGPointMake(0,0)]; [[viewB animator] setFrameOrigin:CGPointMake(200,0)]; } [CPAnimationContext endGrouping]; currentView = 1 - currentView; } @end