Permalink
Browse files

Added Hypnotime from solutions for starting Chapter 22

  • Loading branch information...
1 parent 807ef23 commit ad01aa1cec611097ad61423be136b2690a45dc84 Ryan Blunden committed Jan 17, 2013
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
View
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.

Large diffs are not rendered by default.

Oops, something went wrong.
@@ -0,0 +1,15 @@
+//
+// AppDelegate.h
+// HypnoTime
+//
+// Created by joeconway on 8/30/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import <UIKit/UIKit.h>
+
+@interface AppDelegate : UIResponder <UIApplicationDelegate>
+
+@property (strong, nonatomic) UIWindow *window;
+
+@end
@@ -0,0 +1,77 @@
+//
+// AppDelegate.m
+// HypnoTime
+//
+// Created by joeconway on 8/30/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
+//
+
+#import "AppDelegate.h"
+#import "HypnosisViewController.h"
+#import "TimeViewController.h"
+
+@implementation AppDelegate
+
+@synthesize window = _window;
+
+- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
+{
+ self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
+ // Override point for customization after application launch.
+
+ HypnosisViewController *hvc = [[HypnosisViewController alloc] init];
+ TimeViewController *tvc = [[TimeViewController alloc] init];
+
+ UITabBarController *tabBarController = [[UITabBarController alloc] init];
+
+ NSArray *viewControllers = [NSArray arrayWithObjects:hvc, tvc, nil];
+ [tabBarController setViewControllers:viewControllers];
+
+
+ [[self window] setRootViewController:tabBarController];
+
+ self.window.backgroundColor = [UIColor whiteColor];
+ [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:.
+ */
+}
+
+@end
@@ -2,40 +2,35 @@
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
-
- <key>CFBundleIdentifier</key>
- <string>com.ryanblunden.${PRODUCT_NAME:rfc1034identifier}</string>
-
- <key>CFBundleDevelopmentRegion</key>
- <string>en</string>
- <key>CFBundleExecutable</key>
- <string>${EXECUTABLE_NAME}</string>
- <key>CFBundleInfoDictionaryVersion</key>
- <string>6.0</string>
- <key>CFBundleName</key>
- <string>${PRODUCT_NAME}</string>
- <key>CFBundlePackageType</key>
- <string>APPL</string>
- <key>CFBundleSignature</key>
- <string>????</string>
-
- <key>CFBundleDisplayName</key>
- <string>${PRODUCT_NAME}</string>
- <key>CFBundleVersion</key>
- <string>1.0</string>
- <key>CFBundleShortVersionString</key>
- <string>1.0</string>
- <key>LSRequiresIPhoneOS</key>
- <true/>
- <key>UIRequiredDeviceCapabilities</key>
- <array>
- <string>armv7</string>
- </array>
- <key>UISupportedInterfaceOrientations</key>
- <array>
- <string>UIInterfaceOrientationPortrait</string>
- <string>UIInterfaceOrientationLandscapeLeft</string>
- <string>UIInterfaceOrientationLandscapeRight</string>
- </array>
+ <key>CFBundleDevelopmentRegion</key>
+ <string>en</string>
+ <key>CFBundleDisplayName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundleExecutable</key>
+ <string>${EXECUTABLE_NAME}</string>
+ <key>CFBundleIconFiles</key>
+ <array/>
+ <key>CFBundleIdentifier</key>
+ <string>com.bignerdranch.${PRODUCT_NAME:rfc1034identifier}</string>
+ <key>CFBundleInfoDictionaryVersion</key>
+ <string>6.0</string>
+ <key>CFBundleName</key>
+ <string>${PRODUCT_NAME}</string>
+ <key>CFBundlePackageType</key>
+ <string>APPL</string>
+ <key>CFBundleShortVersionString</key>
+ <string>1.0</string>
+ <key>CFBundleSignature</key>
+ <string>????</string>
+ <key>CFBundleVersion</key>
+ <string>1.0</string>
+ <key>LSRequiresIPhoneOS</key>
+ <true/>
+ <key>UISupportedInterfaceOrientations</key>
+ <array>
+ <string>UIInterfaceOrientationPortrait</string>
+ <string>UIInterfaceOrientationLandscapeLeft</string>
+ <string>UIInterfaceOrientationLandscapeRight</string>
+ </array>
</dict>
-</plist>
+</plist>
@@ -10,7 +10,5 @@
#ifdef __OBJC__
#import <UIKit/UIKit.h>
-
#import <Foundation/Foundation.h>
-
-#endif
+#endif
@@ -1,12 +1,16 @@
//
-// Created by rblunden on 1/14/13.
+// HypnosisView.h
+// Hypnosister
//
-// To change the template use AppCode | Preferences | File Templates.
+// Created by joeconway on 8/11/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
//
-
#import <Foundation/Foundation.h>
-
@interface HypnosisView : UIView
-@end
+{
+
+}
+@property (nonatomic, strong) UIColor *circleColor;
+@end
@@ -1,48 +1,99 @@
//
-// Created by rblunden on 1/14/13.
+// HypnosisView.m
+// Hypnosister
//
-// To change the template use AppCode | Preferences | File Templates.
+// Created by joeconway on 8/11/11.
+// Copyright 2011 __MyCompanyName__. All rights reserved.
//
-
#import "HypnosisView.h"
-
@implementation HypnosisView
-- (id)initWithFrame:(CGRect)frame {
- self = [super initWithFrame:frame];
- if (self) {
- [self setBackgroundColor:[UIColor clearColor]];
- }
- return self;
+@synthesize circleColor;
+
+- (id)initWithFrame:(CGRect)frame
+{
+ self = [super initWithFrame:frame];
+ if(self) {
+ [self setBackgroundColor:[UIColor clearColor]];
+ [self setCircleColor:[UIColor lightGrayColor]];
+ }
+ return self;
+}
+
+- (void)motionBegan:(UIEventSubtype)motion withEvent:(UIEvent *)event
+{
+ if(motion == UIEventSubtypeMotionShake) {
+ NSLog(@"Device started shaking!");
+ [self setCircleColor:[UIColor redColor]];
+ }
}
-- (void)drawRect:(CGRect)dirtyRect {
- CGContextRef ctx = UIGraphicsGetCurrentContext();
- CGRect bounds = [self bounds];
+- (void)setCircleColor:(UIColor *)clr
+{
+ circleColor = clr;
+ [self setNeedsDisplay];
+}
+
+- (BOOL)canBecomeFirstResponder
+{
+ return YES;
+}
+- (void)drawRect:(CGRect)dirtyRect
+{
+ CGContextRef ctx = UIGraphicsGetCurrentContext();
+ CGRect bounds = [self bounds];
+
+ // Figure out the center of the bounds rectangle
+ CGPoint center;
+ center.x = bounds.origin.x + bounds.size.width / 2.0;
+ center.y = bounds.origin.y + bounds.size.height / 2.0;
+
+ // The radius of the circle should be nearly as big as the view
+ float maxRadius = hypot(bounds.size.width, bounds.size.height) / 2.0;
+
+ // The thickness of the line should be 10 points wide
+ CGContextSetLineWidth(ctx, 10);
+
+ [[self circleColor] setStroke];
+
+ // Draw concentric circles from the outside in
+ for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
+ CGContextAddArc(ctx, center.x, center.y, currentRadius, 0.0, M_PI * 2.0, YES);
+
+ CGContextStrokePath(ctx);
+ }
+
+ // Create a string
+ NSString *text = @"You are getting sleepy.";
+
+ // Get a font to draw it in
+ UIFont *font = [UIFont boldSystemFontOfSize:28];
- // Figure out the center of the bounds rectangle
- CGPoint center;
- center.x = bounds.origin.x + bounds.size.width / 2.0;
- center.y = bounds.origin.y + bounds.size.height / 2.0;
+ CGRect textRect;
+
+ // How big is this string when drawn in this font?
+ textRect.size = [text sizeWithFont:font];
+
+ // Let's put that string in the center of the view
+ textRect.origin.x = center.x - textRect.size.width / 2.0;
+ textRect.origin.y = center.y - textRect.size.height / 2.0;
- // The radius of the circle should be nearly as big as the view
- float maxRadius = hypot(bounds.size.width, bounds.size.height) / 2.0;
+ // Set the fill color of the current context to black
+ [[UIColor blackColor] setFill];
- // The thickness of the line should be 10 points wide
- CGContextSetLineWidth(ctx, 10);
+ // The shadow will move 4 points to the right and 3 points down from the text
+ CGSize offset = CGSizeMake(4, 3);
- // The color of the line should be gray (red/ green/ blue = 0.6, alpha = 1.0);
-// CGContextSetRGBStrokeColor(ctx, 0.6, 0.6, 0.6, 1.0);
- [[UIColor lightGrayColor] setStroke];
+ // The shadow will be dark gray in color
+ CGColorRef color = [[UIColor darkGrayColor] CGColor];
- // DRaw concentric circles from the outside in
- for (float currentRadius = maxRadius; currentRadius > 0; currentRadius -= 20) {
- // Add a path to the context
- CGContextAddArc(ctx, center.x, center.y, currentRadius, 0.0, M_PI * 2.0, YES);
+ // Set the shadow of the context with these parameters,
+ // all subsequent drawing will be shadowed
+ CGContextSetShadowWithColor(ctx, offset, 2.0, color);
- // Perform drawing instruction; removes path
- CGContextStrokePath(ctx);
- }
+ // Draw the string
+ [text drawInRect:textRect
+ withFont:font];
}
-@end
+@end
@@ -1,14 +1,13 @@
//
-// Created by rblunden on 1/14/13.
+// HypnosisViewController.h
+// HypnoTime
//
-// To change the template use AppCode | Preferences | File Templates.
+// Created by joeconway on 8/30/11.
+// Copyright (c) 2011 __MyCompanyName__. All rights reserved.
//
-
#import <Foundation/Foundation.h>
-
@interface HypnosisViewController : UIViewController
-@property (nonatomic, strong) UIView *view;
-@end
+@end
Oops, something went wrong.

0 comments on commit ad01aa1

Please sign in to comment.