|
| 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