In this application we will see how to Rectangle moving in the application . We are using here CoreGraphics.framework , for animation behavior. So just have a look.
Step 1: Create a Window base application using template. Give the application name “ChangeRect”.
Step 2: Xcode automatically creates the directory structure and adds essential frameworks to it. You can explore the directory structure to check out the content of the directory.
Step 3: We need to add here UIView class to the project.Choose New file -> Select cocoa touch classes group and then select UIView subclass . Give the name “CreateRectView”.
Step 4: open the AppDelegate.m file, we create a background and set the gray background color and make two different rectangle with different color. So make the following changes in the file:
{
CGRect windowRect = [[UIScreen mainScreen] applicationFrame];
UIWindow *window = [[UIWindow alloc] initWithFrame:windowRect];
[window setBackgroundColor:[UIColor greenColor]];
[self setWindow:window];
CGRect changeRect1 = { 80.0, 100.0, 160.0, 100.0 };
ChangeRectView *changeView1 = [[ChangeRectView alloc] initWithFrame:changeRect1];
[changeView1 setBackgroundColor:[UIColor darkGrayColor]];
CGRect changeRect2 = { 80.0, 300.0, 120.0, 100.0 };
ChangeRectView *changeView2 = [[ChangeRectView alloc] initWithFrame:changeRect2];
[changeView2 setBackgroundColor:[UIColor redColor]];
[window addSubview: changeView2];
[window addSubview: changeView1];
[window makeKeyAndVisible];
[changeView1 ChangeView];
[changeView2 fly];
[window release];
[changeView1 release];
[changeView2 release];
}
Step 5: In the ChangeRectView.h file, we define two methods. Make the following changes in the file:
}
- (void)ChangeView;
- (void)fly;
Step 6: Now open the ChangeRectView.m file and make the changes:
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationRepeatAutoreverses:YES];
[self setTransform:CGAffineTransformMakeRotation(-0.75)];
[UIView commitAnimations];
}
- (void)fly
{
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:0.25];
[UIView setAnimationCurve:UIViewAnimationCurveEaseInOut];
[UIView setAnimationRepeatCount:10];
[UIView setAnimationRepeatAutoreverses:YES];
[self setTransform:CGAffineTransformMakeRotation(-0.75)];
[UIView commitAnimations];
}
Step 7: In the main.m file, we need to provide the name of the AppDelegate class as a argument here. So make the following changes in the file:
NSAutoreleasePool * pool = [[NSAutoreleasePool alloc] init];
int retVal = UIApplicationMain(argc, argv, nil, @"ChangeRectAppDelegate");
[pool release];
return retVal;
}
Step 8: Now compile and run the application in the simulator.

You can downloaded SourceCode from here ChangeRect 2










