Skip to content

Commit 31af80c

Browse files
committed
Update TransitionSample2
1 parent be2991b commit 31af80c

File tree

3 files changed

+269
-52
lines changed

3 files changed

+269
-52
lines changed

TransitionSample2/Classes/TransitionSample2ViewController.h

Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,20 +10,29 @@
1010

1111
@interface TransitionSample2ViewController : UIViewController {
1212

13+
UIView* baseView;
1314
UIImageView* imageView1;
1415
UIImageView* imageView2;
16+
1517
UISlider* slider;
1618
UILabel* duration;
1719

1820
NSMutableArray* images;
1921
NSInteger imageIndex;
2022

23+
UISegmentedControl* mainType;
24+
UISegmentedControl* subType;
2125
}
26+
@property (nonatomic, retain) IBOutlet UIView* baseView;
2227
@property (nonatomic, retain) IBOutlet UIImageView* imageView1;
2328
@property (nonatomic, retain) IBOutlet UIImageView* imageView2;
2429
@property (nonatomic, retain) IBOutlet UISlider* slider;
2530
@property (nonatomic, retain) NSMutableArray* images;
2631
@property (nonatomic, retain) IBOutlet UILabel* duration;
32+
33+
@property (nonatomic, retain) IBOutlet UISegmentedControl* mainType;
34+
@property (nonatomic, retain) IBOutlet UISegmentedControl* subType;
35+
2736
-(IBAction)didChangeDuration:(id)sender;
2837
-(IBAction)doTransition:(id)sender;
2938

TransitionSample2/Classes/TransitionSample2ViewController.m

Lines changed: 13 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,8 +11,10 @@
1111

1212
@implementation TransitionSample2ViewController
1313

14+
@synthesize baseView;
1415
@synthesize imageView1, imageView2, slider,duration;
1516
@synthesize images;
17+
@synthesize mainType, subType;
1618

1719
/*
1820
// The designated initializer. Override to perform setup that is required before the view is loaded.
@@ -76,14 +78,24 @@ - (void)dealloc {
7678

7779
-(IBAction)doTransition:(id)sender;
7880
{
81+
82+
7983
// setup next image
8084
imageIndex = (imageIndex+1)%8;
8185
imageView2.image = [images objectAtIndex:imageIndex];
8286

87+
// transition
8388
CATransition* transition = [CATransition animation];
8489
transition.duration = self.slider.value;
8590
transition.timingFunction = [CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut];
86-
transition.type = kCATransitionFade;
91+
92+
NSString *maintypes[4] = {kCATransitionMoveIn, kCATransitionPush, kCATransitionReveal, kCATransitionFade};
93+
NSString *subtypes[4] = {kCATransitionFromLeft, kCATransitionFromRight, kCATransitionFromTop, kCATransitionFromBottom};
94+
95+
transition.type = maintypes[mainType.selectedSegmentIndex];
96+
if (mainType.selectedSegmentIndex < 3) {
97+
transition.subtype = subtypes[subType.selectedSegmentIndex];
98+
}
8799

88100
[self.view.layer addAnimation:transition forKey:nil];
89101

0 commit comments

Comments
 (0)