在storyboard中,segue有几种不同的类型,在iphone和ipad的开发中,segue的类型是不同的。

在iphone中,segue有:push,modal,和custom三种不同的类型,这些类型的区别在与新页面出现的方式。

而在ipad中,有push,modal,popover,replace和custom五种不同的类型。

根据这几个特点,同时自己有观看了,斯坦福大学的公开课,里面也是有关于此方面的应用。废话少说,将自己的实例放上来吧。

里面的内容大部分跟课程里面的内容差不多

PsychologistViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
//
// PsychologistViewController.m
// Psychologist
//
// Created by david on 13-5-26.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "PsychologistViewController.h"
#import "happinessViewController.h"

@interface PsychologistViewController ()

@property (nonatomic) int diagnosis;

@end

@implementation PsychologistViewController

@synthesize diagnosis = _diagnosis;

-(void) setAndShowDiagnosis:(int)diagnosis
{
self.diagnosis = diagnosis;
[self performSegueWithIdentifier:@"showDiagnosis" sender:self];
}

-(void) prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender
{
if([segue.identifier isEqualToString:@"showDiagnosis"])
{
[segue.destinationViewController setHappiness:self.diagnosis];
}
else if([segue.identifier isEqualToString:@"movie"])
{
[segue.destinationViewController setHappiness:50];
}
else if([segue.identifier isEqualToString:@"teleplay"])
{
[segue.destinationViewController setHappiness:20];
}
else if([segue.identifier isEqualToString:@"cartoon"])
{
[segue.destinationViewController setHappiness:100];
}
}

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

- (IBAction)flaying:(id)sender
{
[self setAndShowDiagnosis:86];
}

- (IBAction)bite:(id)sender
{
[self setAndShowDiagnosis:70];
}

- (IBAction)play:(id)sender
{
[self setAndShowDiagnosis:20];
}
@end
PsychologistViewController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
//
// PsychologistViewController.h
// Psychologist
//
// Created by david on 13-5-26.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface PsychologistViewController : UIViewController
- (IBAction)flaying:(id)sender;
- (IBAction)bite:(id)sender;
- (IBAction)play:(id)sender;

@end
faceView.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
//
// faceView.h
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>


@class faceView;

@protocol FaceViewDataSource
-(float) smileForFaceView:(faceView *) sender;
@end


@interface faceView : UIView

@property (nonatomic) CGFloat scale;
-(void) pinch:(UIPinchGestureRecognizer *)gesture;

@property (nonatomic, weak) IBOutlet id<FaceViewDataSource> dataSource;

@end
faceView.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
//
// faceView.m
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "faceView.h"

#define DEFAULT_SCALE 0.90
#define EYE_H 0.35
#define EYE_V 0.35
#define EYE_RADIUS 0.10
#define MOUTH_H 0.45
#define MOUTH_V 0.40
#define MOUTH_SMILE 0.25


@implementation faceView

@synthesize scale = _scale;

-(CGFloat) scale
{
if(!_scale)
{
return DEFAULT_SCALE;
}else{
return _scale;
}
}


-(void) setScale:(CGFloat)scale
{
if(scale != _scale)
{
_scale = scale;
[self setNeedsDisplay];
}
}

-(void) pinch:(UIPinchGestureRecognizer *)gesture
{
if((gesture.state == UIGestureRecognizerStateChanged) || (gesture.state == UIGestureRecognizerStateEnded))
{
self.scale = gesture.scale;
gesture.scale = 1;
}
}


-(void) setup
{
self.contentMode = UIViewContentModeRedraw;
}

-(void) awakeFromNib
{
[self setup];
}

- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// Initialization code
[self setup];
}
return self;
}

-(void) drawCircleAtPoint:(CGPoint)p withRadius:(CGFloat)radius inContext:(CGContextRef)context
{
UIGraphicsPushContext(context);
CGContextBeginPath(context);
CGContextAddArc(context, p.x, p.y, radius, 0 , 2*M_PI, YES);
CGContextStrokePath(context);
UIGraphicsPopContext();
}

// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{

//face
CGContextRef context = UIGraphicsGetCurrentContext();

CGPoint midPoint;
midPoint.x = self.bounds.origin.x + self.bounds.size.width / 2;
midPoint.y = self.bounds.origin.y + self.bounds.size.height / 2;


CGFloat size = self.bounds.size.width / 2;
if(self.bounds.size.height < self.bounds.size.width) size = self.bounds.size.height / 2;

size *= self.scale;

CGContextSetLineWidth(context, 5.0);
[[UIColor blueColor] setStroke];

[self drawCircleAtPoint:midPoint withRadius:size inContext: context];

//eye
CGPoint eyePoint;
eyePoint.x = midPoint.x - size * EYE_H;
eyePoint.y = midPoint.y - size * EYE_V;
[self drawCircleAtPoint:eyePoint withRadius:size * EYE_RADIUS inContext:context];
eyePoint.x += size * EYE_H * 2;
[self drawCircleAtPoint:eyePoint withRadius:size * EYE_RADIUS inContext:context];


//mouth
CGPoint mouthStartPoint;
mouthStartPoint.x = midPoint.x - size * MOUTH_H;
mouthStartPoint.y = midPoint.y + size * MOUTH_V;
CGPoint mouthEndPoint = mouthStartPoint;
mouthEndPoint.x += MOUTH_H * size * 2;

CGPoint mouthCP1 = mouthStartPoint;
mouthCP1.x += MOUTH_H * size * 2 / 3;

CGPoint mouthCP2 = mouthEndPoint;
mouthCP2.x -= MOUTH_V * size * 2 / 3;

float smile = [self.dataSource smileForFaceView:self];
if(smile < -1) smile = -1;
if(smile > 1) smile = 1;

CGFloat smileOffset = MOUTH_SMILE * size * smile;
mouthCP1.y += smileOffset;
mouthCP2.y += smileOffset;

CGContextBeginPath(context);
CGContextMoveToPoint(context, mouthStartPoint.x, mouthStartPoint.y);
CGContextAddCurveToPoint(context, mouthCP1.x, mouthCP1.y, mouthCP2.x, mouthCP2.y, mouthEndPoint.x, mouthEndPoint.y);
CGContextStrokePath(context);
// Drawing code
}


@end
happinessViewController.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
//
// happinessViewController.m
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import "happinessViewController.h"
#import "faceView.h"

@interface happinessViewController ()<FaceViewDataSource>
@property (weak, nonatomic) IBOutlet faceView *faceView;
@end

@implementation happinessViewController


@synthesize happiness = _happiness;
@synthesize faceView = _faceView;

- (void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view, typically from a nib.
}

-(void) setHappiness:(int)happiness
{
_happiness = happiness;
[self.faceView setNeedsDisplay];
}

-(void) setFaceView:(faceView *)faceView
{
_faceView = faceView;
[self.faceView addGestureRecognizer:[[UIPinchGestureRecognizer alloc] initWithTarget:self.faceView action:@selector(pinch:)]];
[self.faceView addGestureRecognizer:[[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(handleHappinessGesture:)]];
self.faceView.dataSource = self;
}

-(void) handleHappinessGesture:(UIPanGestureRecognizer *)gesture
{
if(gesture.state == UIGestureRecognizerStateChanged || gesture.state == UIGestureRecognizerStateEnded)
{
CGPoint translation = [gesture translationInView:self.faceView];
self.happiness -= translation.y / 2;
[gesture setTranslation:CGPointZero inView:self.faceView];
}
}

-(float) smileForFaceView:(faceView *)sender
{
return (self.happiness - 50.0) / 50.0;
}

- (void)didReceiveMemoryWarning
{
[super didReceiveMemoryWarning];
// Dispose of any resources that can be recreated.
}

-(BOOL) shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
{
return YES;
}

@end
happinessViewController.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
//
// happinessViewController.h
// happiness
//
// Created by david on 13-5-23.
// Copyright (c) 2013年 david. All rights reserved.
//

#import <UIKit/UIKit.h>

@interface happinessViewController : UIViewController

@property (nonatomic) int happiness; //0 代表不开心 100 代表开心

@end

应用截图相册地址:http://my.poco.cn/album/album\_show\_photo\_list.htx&user\_id=173673909&set\_hash=3946768073