Skip to content
Browse files

Merge pull request #1 from atnan/master

Fixed two memory leaks & made some code-style changes
  • Loading branch information...
2 parents 7210ea3 + 1c9fa05 commit e9ee7f55b45b69412aa863e7394f16f32c8ef1fe @crafterm committed May 14, 2011
Showing with 138 additions and 192 deletions.
  1. +1 −3 IconApp/IconAppAppDelegate.h
  2. +5 −47 IconApp/IconAppAppDelegate.m
  3. +0 −1 IconApp/IconView.h
  4. +131 −139 IconApp/IconView.m
  5. +0 −1 IconApp/IconViewController.h
  6. +1 −1 IconApp/IconViewController.m
View
4 IconApp/IconAppAppDelegate.h
@@ -8,9 +8,7 @@
#import <UIKit/UIKit.h>
-@interface IconAppAppDelegate : NSObject <UIApplicationDelegate> {
-
-}
+@interface IconAppAppDelegate : NSObject <UIApplicationDelegate>
@property (nonatomic, retain) IBOutlet UIWindow *window;
View
52 IconApp/IconAppAppDelegate.m
@@ -11,60 +11,18 @@
@implementation IconAppAppDelegate
-
@synthesize window=_window;
-- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
-{
- // Override point for customization after application launch.
- IconViewController * iconViewController = [[IconViewController alloc] init];
- [self.window addSubview:iconViewController.view];
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
+ self.window.rootViewController = [[[IconViewController alloc] init] autorelease];
[self.window makeKeyAndVisible];
+
return YES;
}
-- (void)applicationWillResignActive:(UIApplication *)application
-{
- /*
- Sent when the application is about to move from active to inactive state. This can occur for certain types of temporary interruptions (such as an incoming phone call or SMS message) or when the user quits the application and it begins the transition to the background state.
- Use this method to pause ongoing tasks, disable timers, and throttle down OpenGL ES frame rates. Games should use this method to pause the game.
- */
-}
-
-- (void)applicationDidEnterBackground:(UIApplication *)application
-{
- /*
- Use this method to release shared resources, save user data, invalidate timers, and store enough application state information to restore your application to its current state in case it is terminated later.
- If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
- */
-}
-
-- (void)applicationWillEnterForeground:(UIApplication *)application
-{
- /*
- Called as part of the transition from the background to the inactive state; here you can undo many of the changes made on entering the background.
- */
-}
-
-- (void)applicationDidBecomeActive:(UIApplication *)application
-{
- /*
- Restart any tasks that were paused (or not yet started) while the application was inactive. If the application was previously in the background, optionally refresh the user interface.
- */
-}
-
-- (void)applicationWillTerminate:(UIApplication *)application
-{
- /*
- Called when the application is about to terminate.
- Save data if appropriate.
- See also applicationDidEnterBackground:.
- */
-}
-
-- (void)dealloc
-{
+- (void)dealloc {
[_window release];
+
[super dealloc];
}
View
1 IconApp/IconView.h
@@ -8,6 +8,5 @@
#import <UIKit/UIKit.h>
-
@interface IconView : UIView
@end
View
270 IconApp/IconView.m
@@ -10,11 +10,6 @@
#import "IconView.h"
-@interface IconView ()
-@property (nonatomic, readonly) CGRect nativeRect;
-@end
-
-
@implementation IconView
- (id)initWithFrame:(CGRect)frame {
@@ -28,140 +23,137 @@ - (id)initWithFrame:(CGRect)frame {
- (void)drawRect:(CGRect)rect {
CGContextRef context = UIGraphicsGetCurrentContext();
- CGContextSaveGState(context);
-
- // determine aspect ratio and scale from native resolution to current bounds size
-
- CGSize boundsSize = self.bounds.size;
- CGSize nativeSize = self.nativeRect.size;
- CGFloat nativeAspect = nativeSize.width / nativeSize.height;
- CGFloat boundsAspect = boundsSize.width / boundsSize.height;
- CGFloat scale = nativeAspect > boundsAspect ?
- boundsSize.width / nativeSize.width :
- boundsSize.height / nativeSize.height;
-
- // transform to current bounds
- CGContextTranslateCTM(context,
- 0.5 * (boundsSize.width - scale * nativeSize.width),
- 0.5 * (boundsSize.height - scale * nativeSize.height));
- CGContextScaleCTM(context, scale, scale);
-
- // circle with shadow
- CGColorSpaceRef colourspace = CGColorSpaceCreateDeviceGray();
- CGFloat shadowComponents[] = { 0.0, 0.75 };
- CGColorRef shadowColor = CGColorCreate(colourspace, shadowComponents);
- CGContextSetShadowWithColor(context, CGSizeMake(0, 8 * scale), 12 * scale, shadowColor);
- CGContextSetGrayFillColor(context, 0.9, 1.0);
- CGContextFillEllipseInRect(context, self.nativeRect);
- CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 0, NULL); // disable shadow
- CGColorRelease(shadowColor);
- CGColorSpaceRelease(colourspace);
-
- // inner circle with gradient
- CGContextSaveGState(context);
- CGContextAddEllipseInRect(context, self.nativeRect);
- CGContextClip(context);
-
- colourspace = CGColorSpaceCreateDeviceGray();
- CGFloat components[] = { 1.0, 1.0, 0.82, 1.0 };
- CGGradientRef gradient = CGGradientCreateWithColorComponents(colourspace, components, NULL, 2);
- CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, nativeSize.height), 0);
- CGGradientRelease(gradient);
- CGColorSpaceRelease(colourspace);
- CGContextRestoreGState(context);
-
- // black center, inset within larger circle
- CGRect ellipseCenterRect = CGRectInset(self.nativeRect, 16, 16);
- CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
- CGContextFillEllipseInRect(context, ellipseCenterRect);
- CGContextAddEllipseInRect(context, ellipseCenterRect);
- CGContextClip(context);
-
-
- // bottom glow gradient
- colourspace = CGColorSpaceCreateDeviceRGB();
- CGFloat bComponents[] = { 0.0, 0.94, 0.82, 1.0,
- 0.0, 0.62, 0.56, 1.0,
- 0.0, 0.05, 0.35, 1.0,
- 0.0, 0.00, 0.00, 1.0 };
- CGFloat bGlocations[] = { 0.0, 0.35, 0.60, 0.7 };
- gradient = CGGradientCreateWithColorComponents(colourspace, bComponents, bGlocations, 4);
- CGPoint centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect) + (CGRectGetHeight(ellipseCenterRect) * 0.1));
- CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
- CGGradientRelease(gradient);
-
- // top glow gradient
- CGFloat tComponents[] = { 0.0, 0.68, 1.00, 0.75,
- 0.0, 0.45, 0.62, 0.55,
- 0.0, 0.45, 0.62, 0.00 };
- CGFloat tGlocations[] = { 0.0, 0.25, 0.40 };
- gradient = CGGradientCreateWithColorComponents(colourspace, tComponents, tGlocations, 3);
- centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect) - (CGRectGetHeight(ellipseCenterRect) * 0.2));
- CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
- CGGradientRelease(gradient);
-
- // center glow gradient
- CGFloat cComponents[] = { 0.0, 0.90, 0.90, 0.90,
- 0.0, 0.49, 1.00, 0.00 };
- CGFloat cGlocations[] = { 0.0, 0.85 };
- gradient = CGGradientCreateWithColorComponents(colourspace, cComponents, cGlocations, 2);
- centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect));
- CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
- CGGradientRelease(gradient);
- CGColorSpaceRelease(colourspace);
-
- // floral shadow
- CGContextSaveGState(context);
- CGContextSetShadowWithColor(context, CGSizeZero, 12 * scale, [UIColor blackColor].CGColor);
-
- // draw floral heart
- NSString * floralHeart = @"\u2766";
- UIFont * floralHeartFont = [UIFont fontWithName:@"Arial Unicode MS" size:420];
- CGSize textSize = [floralHeart sizeWithFont:floralHeartFont];
-
- CGPoint point = CGPointMake((CGRectGetWidth(ellipseCenterRect) - textSize.width) / 2.0,
- (CGRectGetHeight(ellipseCenterRect) - textSize.height) / 2.0);
-
- CGContextSetGrayFillColor(context, 0.9, 1.0);
- [floralHeart drawAtPoint:point withFont:floralHeartFont];
-
- CGContextRestoreGState(context);
-
- // gloss arc
- const CGFloat glossInset = 8;
- CGFloat glossRadius = (CGRectGetWidth(ellipseCenterRect) * 0.5) - glossInset;
- double arcFraction = 0.1;
-
- CGPoint topArcCenter = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect));
- CGPoint arcStartPoint = CGPointMake(topArcCenter.x + glossRadius * cos((2 * M_PI) - arcFraction),
- topArcCenter.y + glossRadius * sin((2 * M_PI) - arcFraction));
- CGContextAddArc(context, topArcCenter.x, topArcCenter.y, glossRadius, (2 * M_PI) - arcFraction, M_PI + arcFraction, 1);
-
- const CGFloat bottomArcBulgeDistance = 70;
- CGContextAddQuadCurveToPoint(context, topArcCenter.x, topArcCenter.y + bottomArcBulgeDistance, arcStartPoint.x, arcStartPoint.y);
- CGContextClip(context);
-
- colourspace = CGColorSpaceCreateDeviceGray();
- CGFloat glossLocations[] = { 0.0, 0.5, 1.0 };
- CGFloat glossComponents[] = { 1.0, 0.85, 1.0, 0.50, 1.0, 0.05 };
- gradient = CGGradientCreateWithColorComponents(colourspace, glossComponents, glossLocations, 3);
-
- CGRect clippedRect = CGContextGetClipBoundingBox(context);
- CGContextDrawLinearGradient(context,
- gradient,
- CGPointMake(topArcCenter.x, CGRectGetMinY(clippedRect)),
- CGPointMake(topArcCenter.x, CGRectGetMaxY(clippedRect)),
- 0);
-
- CGGradientRelease(gradient);
- CGColorSpaceRelease(colourspace);
-
- // all done
- CGContextRestoreGState(context);
-}
-
-- (CGRect)nativeRect {
- return CGRectMake(0, 0, 512, 512);
+ static CGRect nativeRect = { 0.f, 0.f, 512.f, 512.f };
+
+ CGContextSaveGState(context); {
+
+ // determine aspect ratio and scale from native resolution to current bounds size
+ CGSize boundsSize = self.bounds.size;
+ CGSize nativeSize = nativeRect.size;
+ CGFloat nativeAspect = nativeSize.width / nativeSize.height;
+ CGFloat boundsAspect = boundsSize.width / boundsSize.height;
+ CGFloat scale = (nativeAspect > boundsAspect ?
+ boundsSize.width / nativeSize.width :
+ boundsSize.height / nativeSize.height);
+
+ // transform to current bounds
+ CGContextTranslateCTM(context,
+ 0.5 * (boundsSize.width - scale * nativeSize.width),
+ 0.5 * (boundsSize.height - scale * nativeSize.height));
+ CGContextScaleCTM(context, scale, scale);
+
+ // circle with shadow
+ CGColorSpaceRef colourspace = CGColorSpaceCreateDeviceGray();
+ CGFloat shadowComponents[] = { 0.0, 0.75 };
+ CGColorRef shadowColor = CGColorCreate(colourspace, shadowComponents);
+ CGContextSetShadowWithColor(context, CGSizeMake(0, 8 * scale), 12 * scale, shadowColor);
+ CGContextSetGrayFillColor(context, 0.9, 1.0);
+ CGContextFillEllipseInRect(context, nativeRect);
+ CGContextSetShadowWithColor(context, CGSizeMake(0, 0), 0, NULL); // disable shadow
+ CGColorRelease(shadowColor);
+ CGColorSpaceRelease(colourspace);
+
+ CGContextSaveGState(context); {
+
+ // inner circle with gradient
+ CGContextAddEllipseInRect(context, nativeRect);
+ CGContextClip(context);
+
+ colourspace = CGColorSpaceCreateDeviceGray();
+ CGFloat components[] = { 1.0, 1.0, 0.82, 1.0 };
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(colourspace, components, NULL, 2);
+ CGContextDrawLinearGradient(context, gradient, CGPointMake(0, 0), CGPointMake(0, nativeSize.height), 0);
+ CGGradientRelease(gradient);
+ CGColorSpaceRelease(colourspace);
+
+ } CGContextRestoreGState(context);
+
+ // black center, inset within larger circle
+ CGRect ellipseCenterRect = CGRectInset(nativeRect, 16, 16);
+ CGContextSetFillColorWithColor(context, [UIColor blackColor].CGColor);
+ CGContextFillEllipseInRect(context, ellipseCenterRect);
+ CGContextAddEllipseInRect(context, ellipseCenterRect);
+ CGContextClip(context);
+
+ // bottom glow gradient
+ colourspace = CGColorSpaceCreateDeviceRGB();
+ CGFloat bComponents[] = { 0.0, 0.94, 0.82, 1.0,
+ 0.0, 0.62, 0.56, 1.0,
+ 0.0, 0.05, 0.35, 1.0,
+ 0.0, 0.00, 0.00, 1.0 };
+ CGFloat bGlocations[] = { 0.0, 0.35, 0.60, 0.7 };
+ CGGradientRef gradient = CGGradientCreateWithColorComponents(colourspace, bComponents, bGlocations, 4);
+ CGPoint centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect) + (CGRectGetHeight(ellipseCenterRect) * 0.1));
+ CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
+ CGGradientRelease(gradient);
+
+ // top glow gradient
+ CGFloat tComponents[] = { 0.0, 0.68, 1.00, 0.75,
+ 0.0, 0.45, 0.62, 0.55,
+ 0.0, 0.45, 0.62, 0.00 };
+ CGFloat tGlocations[] = { 0.0, 0.25, 0.40 };
+ gradient = CGGradientCreateWithColorComponents(colourspace, tComponents, tGlocations, 3);
+ centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect) - (CGRectGetHeight(ellipseCenterRect) * 0.2));
+ CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
+ CGGradientRelease(gradient);
+
+ // center glow gradient
+ CGFloat cComponents[] = { 0.0, 0.90, 0.90, 0.90,
+ 0.0, 0.49, 1.00, 0.00 };
+ CGFloat cGlocations[] = { 0.0, 0.85 };
+ gradient = CGGradientCreateWithColorComponents(colourspace, cComponents, cGlocations, 2);
+ centerPoint = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect));
+ CGContextDrawRadialGradient(context, gradient, centerPoint, 0.0, centerPoint, CGRectGetHeight(ellipseCenterRect) * 0.8, 0);
+ CGGradientRelease(gradient);
+ CGColorSpaceRelease(colourspace);
+
+ CGContextSaveGState(context); {
+ // floral shadow
+ CGContextSetShadowWithColor(context, CGSizeZero, 12 * scale, [UIColor blackColor].CGColor);
+
+ // draw floral heart
+ NSString * floralHeart = @"\u2766";
+ UIFont * floralHeartFont = [UIFont fontWithName:@"Arial Unicode MS" size:420];
+ CGSize textSize = [floralHeart sizeWithFont:floralHeartFont];
+
+ CGPoint point = CGPointMake((CGRectGetWidth(ellipseCenterRect) - textSize.width) / 2.0,
+ (CGRectGetHeight(ellipseCenterRect) - textSize.height) / 2.0);
+
+ CGContextSetGrayFillColor(context, 0.9, 1.0);
+ [floralHeart drawAtPoint:point withFont:floralHeartFont];
+
+ } CGContextRestoreGState(context);
+
+ // gloss arc
+ const CGFloat glossInset = 8;
+ CGFloat glossRadius = (CGRectGetWidth(ellipseCenterRect) * 0.5) - glossInset;
+ double arcFraction = 0.1;
+
+ CGPoint topArcCenter = CGPointMake(CGRectGetMidX(ellipseCenterRect), CGRectGetMidY(ellipseCenterRect));
+ CGPoint arcStartPoint = CGPointMake(topArcCenter.x + glossRadius * cos((2 * M_PI) - arcFraction),
+ topArcCenter.y + glossRadius * sin((2 * M_PI) - arcFraction));
+ CGContextAddArc(context, topArcCenter.x, topArcCenter.y, glossRadius, (2 * M_PI) - arcFraction, M_PI + arcFraction, 1);
+
+ const CGFloat bottomArcBulgeDistance = 70;
+ CGContextAddQuadCurveToPoint(context, topArcCenter.x, topArcCenter.y + bottomArcBulgeDistance, arcStartPoint.x, arcStartPoint.y);
+ CGContextClip(context);
+
+ colourspace = CGColorSpaceCreateDeviceGray();
+ CGFloat glossLocations[] = { 0.0, 0.5, 1.0 };
+ CGFloat glossComponents[] = { 1.0, 0.85, 1.0, 0.50, 1.0, 0.05 };
+ gradient = CGGradientCreateWithColorComponents(colourspace, glossComponents, glossLocations, 3);
+
+ CGRect clippedRect = CGContextGetClipBoundingBox(context);
+ CGContextDrawLinearGradient(context,
+ gradient,
+ CGPointMake(topArcCenter.x, CGRectGetMinY(clippedRect)),
+ CGPointMake(topArcCenter.x, CGRectGetMaxY(clippedRect)),
+ 0);
+
+ CGGradientRelease(gradient);
+ CGColorSpaceRelease(colourspace);
+
+ } CGContextRestoreGState(context);
}
@end
View
1 IconApp/IconViewController.h
@@ -8,7 +8,6 @@
#import <UIKit/UIKit.h>
-
@interface IconViewController : UIViewController
@end
View
2 IconApp/IconViewController.m
@@ -14,7 +14,7 @@ @implementation IconViewController
#pragma mark - View lifecycle
- (void)loadView {
- self.view = [[IconView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
+ self.view = [[[IconView alloc] initWithFrame:[[UIScreen mainScreen] applicationFrame]] autorelease];
}
@end

0 comments on commit e9ee7f5

Please sign in to comment.
Something went wrong with that request. Please try again.