Skip to content

Commit ab692f6

Browse files
committed
Added TransitionSample
1 parent 0a4b986 commit ab692f6

19 files changed

+1909
-0
lines changed
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,22 @@
1+
//
2+
// TransitionSampleAppDelegate.h
3+
// TransitionSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/10/14.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@class TransitionSampleViewController;
12+
13+
@interface TransitionSampleAppDelegate : NSObject <UIApplicationDelegate> {
14+
UIWindow *window;
15+
TransitionSampleViewController *viewController;
16+
}
17+
18+
@property (nonatomic, retain) IBOutlet UIWindow *window;
19+
@property (nonatomic, retain) IBOutlet TransitionSampleViewController *viewController;
20+
21+
@end
22+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,88 @@
1+
//
2+
// TransitionSampleAppDelegate.m
3+
// TransitionSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/10/14.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import "TransitionSampleAppDelegate.h"
10+
#import "TransitionSampleViewController.h"
11+
12+
@implementation TransitionSampleAppDelegate
13+
14+
@synthesize window;
15+
@synthesize viewController;
16+
17+
18+
#pragma mark -
19+
#pragma mark Application lifecycle
20+
21+
- (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
22+
23+
// Override point for customization after application launch.
24+
25+
// Add the view controller's view to the window and display.
26+
[window addSubview:viewController.view];
27+
[window makeKeyAndVisible];
28+
29+
return YES;
30+
}
31+
32+
33+
- (void)applicationWillResignActive:(UIApplication *)application {
34+
/*
35+
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.
36+
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.
37+
*/
38+
}
39+
40+
41+
- (void)applicationDidEnterBackground:(UIApplication *)application {
42+
/*
43+
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.
44+
If your application supports background execution, called instead of applicationWillTerminate: when the user quits.
45+
*/
46+
}
47+
48+
49+
- (void)applicationWillEnterForeground:(UIApplication *)application {
50+
/*
51+
Called as part of transition from the background to the inactive state: here you can undo many of the changes made on entering the background.
52+
*/
53+
}
54+
55+
56+
- (void)applicationDidBecomeActive:(UIApplication *)application {
57+
/*
58+
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.
59+
*/
60+
}
61+
62+
63+
- (void)applicationWillTerminate:(UIApplication *)application {
64+
/*
65+
Called when the application is about to terminate.
66+
See also applicationDidEnterBackground:.
67+
*/
68+
}
69+
70+
71+
#pragma mark -
72+
#pragma mark Memory management
73+
74+
- (void)applicationDidReceiveMemoryWarning:(UIApplication *)application {
75+
/*
76+
Free up as much memory as possible by purging cached data objects that can be recreated (or reloaded from disk) later.
77+
*/
78+
}
79+
80+
81+
- (void)dealloc {
82+
[viewController release];
83+
[window release];
84+
[super dealloc];
85+
}
86+
87+
88+
@end
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,35 @@
1+
//
2+
// TransitionSampleViewController.h
3+
// TransitionSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/10/14.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import <UIKit/UIKit.h>
10+
11+
@interface TransitionSampleViewController : UIViewController {
12+
13+
UIImageView* imageView;
14+
15+
NSMutableArray* images;
16+
17+
NSInteger imageIndex;
18+
19+
UISlider* slider;
20+
21+
UILabel* duration;
22+
}
23+
@property (nonatomic, retain) IBOutlet UIImageView* imageView;
24+
@property (nonatomic, retain) IBOutlet NSMutableArray* images;
25+
@property (nonatomic, retain) IBOutlet UISlider* slider;
26+
@property (nonatomic, retain) IBOutlet UILabel* duration;
27+
28+
-(IBAction)none:(id)sender;
29+
-(IBAction)flipFromLeft:(id)sender;
30+
-(IBAction)flipFromRight:(id)sender;
31+
-(IBAction)curlUp:(id)sender;
32+
-(IBAction)curlDown:(id)sender;
33+
-(IBAction)didChangeDuration:(id)sender;
34+
@end
35+
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,121 @@
1+
//
2+
// TransitionSampleViewController.m
3+
// TransitionSample
4+
//
5+
// Created by Hiroshi Hashiguchi on 10/10/14.
6+
// Copyright 2010 . All rights reserved.
7+
//
8+
9+
#import "TransitionSampleViewController.h"
10+
11+
@implementation TransitionSampleViewController
12+
@synthesize imageView;
13+
@synthesize images;
14+
@synthesize slider;
15+
@synthesize duration;
16+
17+
/*
18+
// The designated initializer. Override to perform setup that is required before the view is loaded.
19+
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil {
20+
if ((self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil])) {
21+
// Custom initialization
22+
}
23+
return self;
24+
}
25+
*/
26+
27+
/*
28+
// Implement loadView to create a view hierarchy programmatically, without using a nib.
29+
- (void)loadView {
30+
}
31+
*/
32+
33+
34+
// Implement viewDidLoad to do additional setup after loading the view, typically from a nib.
35+
- (void)viewDidLoad {
36+
[super viewDidLoad];
37+
38+
self.images = [NSMutableArray array];
39+
40+
for (int i=1; i <= 8; i++) {
41+
NSString* filename = [NSString stringWithFormat:@"image%02d.jpg", i];
42+
UIImage* image = [UIImage imageNamed:filename];
43+
[self.images addObject:image];
44+
}
45+
imageIndex = 0;
46+
self.imageView.image = [self.images objectAtIndex:imageIndex];
47+
duration.text = [NSString stringWithFormat:@"%.1f", self.slider.value];
48+
}
49+
50+
51+
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
52+
return YES;
53+
}
54+
55+
- (void)didReceiveMemoryWarning {
56+
// Releases the view if it doesn't have a superview.
57+
[super didReceiveMemoryWarning];
58+
59+
// Release any cached data, images, etc that aren't in use.
60+
}
61+
62+
- (void)viewDidUnload {
63+
// Release any retained subviews of the main view.
64+
// e.g. self.myOutlet = nil;
65+
}
66+
67+
68+
- (void)dealloc {
69+
[super dealloc];
70+
}
71+
72+
73+
- (void)doTransition:(UIViewAnimationTransition)transition
74+
{
75+
[UIView beginAnimations:nil context:nil];
76+
77+
[UIView setAnimationTransition:transition
78+
forView:self.imageView
79+
cache:NO];
80+
[UIView setAnimationDuration:self.slider.value];
81+
imageIndex = (imageIndex+1)%8;
82+
self.imageView.image = [self.images objectAtIndex:imageIndex];
83+
84+
85+
[UIView commitAnimations];
86+
}
87+
88+
-(IBAction)none:(id)sender
89+
{
90+
[self doTransition:UIViewAnimationTransitionNone];
91+
}
92+
93+
94+
-(IBAction)flipFromLeft:(id)sender
95+
{
96+
[self doTransition:UIViewAnimationTransitionFlipFromLeft];
97+
}
98+
99+
-(IBAction)flipFromRight:(id)sender
100+
{
101+
[self doTransition:UIViewAnimationTransitionFlipFromRight];
102+
}
103+
104+
-(IBAction)curlUp:(id)sender
105+
{
106+
[self doTransition:UIViewAnimationTransitionCurlUp];
107+
}
108+
109+
-(IBAction)curlDown:(id)sender
110+
{
111+
[self doTransition:UIViewAnimationTransitionCurlDown];
112+
}
113+
114+
-(IBAction)didChangeDuration:(id)sender
115+
{
116+
NSLog(@"%f", self.slider.value);
117+
duration.text = [NSString stringWithFormat:@"%.1f", self.slider.value];
118+
119+
}
120+
121+
@end

0 commit comments

Comments
 (0)