Skip to content

Commit

Permalink
Episode 88
Browse files Browse the repository at this point in the history
  • Loading branch information
subdigital committed Sep 24, 2013
1 parent 4dc9246 commit 92342d6
Show file tree
Hide file tree
Showing 38 changed files with 2,071 additions and 0 deletions.

Large diffs are not rendered by default.

Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// AppDelegate.h
// SimpleTransitions
//
// Created by ben on 9/14/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface AppDelegate : UIResponder <UIApplicationDelegate>

@property (strong, nonatomic) UIWindow *window;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,42 @@
//
// AppDelegate.m
// SimpleTransitions
//
// Created by ben on 9/14/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import "AppDelegate.h"
#import "TransitionListViewController.h"

@implementation AppDelegate

- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions
{
self.window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];

TransitionListViewController *transitionVC = [[TransitionListViewController alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:transitionVC];
self.window.rootViewController = nav;

self.window.backgroundColor = [UIColor whiteColor];
[self.window makeKeyAndVisible];
return YES;
}

- (void)applicationWillResignActive:(UIApplication *)application {
}

- (void)applicationDidEnterBackground:(UIApplication *)application {
}

- (void)applicationWillEnterForeground:(UIApplication *)application {
}

- (void)applicationDidBecomeActive:(UIApplication *)application {
}

- (void)applicationWillTerminate:(UIApplication *)application {
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,15 @@
//
// ColorViewController.h
// SimpleTransitions
//
// Created by ben on 9/15/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface ColorViewController : UIViewController

- (id)initWithColor:(UIColor *)color;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,68 @@
//
// ColorViewController.m
// SimpleTransitions
//
// Created by ben on 9/15/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import "ColorViewController.h"

@interface ColorViewController ()
@property (nonatomic, strong) UIColor *color;
@end

@implementation ColorViewController

- (id)initWithColor:(UIColor *)color {
self = [super init];
if (self) {
self.color = color;
self.modalPresentationStyle = UIModalPresentationCustom;
}
return self;
}

- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = self.color;
self.view.layer.borderColor = [[UIColor blackColor] CGColor];
self.view.layer.borderWidth = 1.0;

UIButton *dismissButton = [UIButton buttonWithType:UIButtonTypeCustom];
dismissButton.tintColor = [UIColor blueColor];
[dismissButton setTitle:@"Back" forState:UIControlStateNormal];

[self.view addSubview:dismissButton];
dismissButton.frame = CGRectMake(0, self.view.frame.size.height - 50, self.view.frame.size.width, 50);
dismissButton.backgroundColor = [UIColor whiteColor];
[dismissButton setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[dismissButton addTarget:self action:@selector(dismiss:) forControlEvents:UIControlEventTouchUpInside];

UITapGestureRecognizer *tapRecognizer = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(onTap:)];
[self.view addGestureRecognizer:tapRecognizer];
}

- (UIColor *)randomColor {
return [UIColor colorWithRed:(arc4random() % 255) / 255.0
green:(arc4random() % 255) / 255.0
blue:(arc4random() % 255) / 255.0
alpha:1.0];
}

- (void)onTap:(id)sender {
ColorViewController *nextColor = [[ColorViewController alloc] initWithColor:[self randomColor]];
nextColor.transitioningDelegate = self.transitioningDelegate;
[self presentViewController:nextColor animated:YES completion:nil];
}

- (void)dismiss:(id)sender {
[self dismissViewControllerAnimated:YES completion:nil];
}

- (void)viewWillAppear:(BOOL)animated {
[super viewWillAppear:animated];
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent animated:YES];
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"idiom" : "iphone",
"size" : "29x29",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "40x40",
"scale" : "2x"
},
{
"idiom" : "iphone",
"size" : "60x60",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,23 @@
{
"images" : [
{
"orientation" : "portrait",
"idiom" : "iphone",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
},
{
"orientation" : "portrait",
"idiom" : "iphone",
"subtype" : "retina4",
"extent" : "full-screen",
"minimum-system-version" : "7.0",
"scale" : "2x"
}
],
"info" : {
"version" : 1,
"author" : "xcode"
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,36 @@
<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
<plist version="1.0">
<dict>
<key>CFBundleDevelopmentRegion</key>
<string>en</string>
<key>CFBundleDisplayName</key>
<string>${PRODUCT_NAME}</string>
<key>CFBundleExecutable</key>
<string>${EXECUTABLE_NAME}</string>
<key>CFBundleIdentifier</key>
<string>com.ficklebits.${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>UIRequiredDeviceCapabilities</key>
<array>
<string>armv7</string>
</array>
<key>UISupportedInterfaceOrientations</key>
<array>
<string>UIInterfaceOrientationPortrait</string>
</array>
</dict>
</plist>
Original file line number Diff line number Diff line change
@@ -0,0 +1,16 @@
//
// Prefix header
//
// The contents of this file are implicitly included at the beginning of every source file.
//

#import <Availability.h>

#ifndef __IPHONE_3_0
#warning "This project uses features only available in iOS SDK 3.0 and later."
#endif

#ifdef __OBJC__
#import <UIKit/UIKit.h>
#import <Foundation/Foundation.h>
#endif
Original file line number Diff line number Diff line change
@@ -0,0 +1,20 @@
//
// SwatchTransition.h
// SimpleTransitions
//
// Created by ben on 9/15/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import <Foundation/Foundation.h>

typedef NS_ENUM(NSInteger, SwatchTransitionMode){
SwatchTransitionModePresent = 0,
SwatchTransitionModeDismiss
};

@interface SwatchTransition : NSObject <UIViewControllerAnimatedTransitioning>

@property (nonatomic, assign) SwatchTransitionMode mode;

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,58 @@
//
// SwatchTransition.m
// SimpleTransitions
//
// Created by ben on 9/15/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import "SwatchTransition.h"
const CGFloat SWATCH_PRESENT_DURATION = 1.5;
const CGFloat SWATCH_DISMISS_DURATION = 0.25;

@implementation SwatchTransition

- (NSTimeInterval)transitionDuration:(id <UIViewControllerContextTransitioning>)transitionContext {
return self.mode == SwatchTransitionModePresent ? SWATCH_PRESENT_DURATION : SWATCH_DISMISS_DURATION;
}

- (void)animateTransition:(id <UIViewControllerContextTransitioning>)transitionContext {
UIViewController *fromVC = [transitionContext viewControllerForKey:UITransitionContextFromViewControllerKey];
UIViewController *toVC = [transitionContext viewControllerForKey:UITransitionContextToViewControllerKey];

CGRect sourceRect = [transitionContext initialFrameForViewController:fromVC];

CGAffineTransform rotation = CGAffineTransformMakeRotation(- M_PI / 2);
UIView *container = [transitionContext containerView];

if (self.mode == SwatchTransitionModePresent) {
[container addSubview:toVC.view];

toVC.view.layer.anchorPoint = CGPointZero;
toVC.view.frame = sourceRect;
toVC.view.transform = rotation;

[UIView animateWithDuration:SWATCH_PRESENT_DURATION
delay:0
usingSpringWithDamping:0.25
initialSpringVelocity:3
options:UIViewAnimationOptionCurveEaseIn
animations:^{
toVC.view.transform = CGAffineTransformIdentity;
} completion:^(BOOL finished) {
[transitionContext completeTransition:YES];
}];
} else if(self.mode == SwatchTransitionModeDismiss) {
[UIView animateWithDuration:SWATCH_DISMISS_DURATION
delay:0
options:UIViewAnimationOptionCurveEaseIn
animations:^{
fromVC.view.transform = rotation;
} completion:^(BOOL finished) {
[fromVC.view removeFromSuperview];
[transitionContext completeTransition:YES];
}];
}
}

@end
Original file line number Diff line number Diff line change
@@ -0,0 +1,13 @@
//
// TransitionListViewController.h
// SimpleTransitions
//
// Created by ben on 9/14/13.
// Copyright (c) 2013 Fickle Bits. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface TransitionListViewController : UITableViewController

@end
Loading

0 comments on commit 92342d6

Please sign in to comment.