├── 2017-06-22 17_47_06.gif
├── README.md
├── SCN3DPlayer.xcodeproj
├── project.pbxproj
├── project.xcworkspace
│ ├── contents.xcworkspacedata
│ └── xcuserdata
│ │ └── taiyoshimichi.xcuserdatad
│ │ └── UserInterfaceState.xcuserstate
└── xcuserdata
│ └── taiyoshimichi.xcuserdatad
│ ├── xcdebugger
│ └── Breakpoints_v2.xcbkptlist
│ └── xcschemes
│ ├── SCN3DPlayer.xcscheme
│ └── xcschememanagement.plist
├── SCN3DPlayer
├── AppDelegate.h
├── AppDelegate.m
├── Assets.xcassets
│ └── AppIcon.appiconset
│ │ └── Contents.json
├── Base.lproj
│ ├── LaunchScreen.storyboard
│ └── Main.storyboard
├── HelloViewController.h
├── HelloViewController.m
├── Info.plist
├── Masonry
│ ├── MASCompositeConstraint.h
│ ├── MASCompositeConstraint.m
│ ├── MASConstraint+Private.h
│ ├── MASConstraint.h
│ ├── MASConstraint.m
│ ├── MASConstraintMaker.h
│ ├── MASConstraintMaker.m
│ ├── MASLayoutConstraint.h
│ ├── MASLayoutConstraint.m
│ ├── MASUtilities.h
│ ├── MASViewAttribute.h
│ ├── MASViewAttribute.m
│ ├── MASViewConstraint.h
│ ├── MASViewConstraint.m
│ ├── Masonry.h
│ ├── NSArray+MASAdditions.h
│ ├── NSArray+MASAdditions.m
│ ├── NSArray+MASShorthandAdditions.h
│ ├── NSLayoutConstraint+MASDebugAdditions.h
│ ├── NSLayoutConstraint+MASDebugAdditions.m
│ ├── View+MASAdditions.h
│ ├── View+MASAdditions.m
│ ├── View+MASShorthandAdditions.h
│ ├── ViewController+MASAdditions.h
│ └── ViewController+MASAdditions.m
├── SCN3DPlayer
│ ├── SCN3DPlayerView.h
│ ├── SCN3DPlayerView.m
│ ├── SCN3DVideoAdatper.h
│ └── SCN3DVideoAdatper.m
├── ViewController.h
├── ViewController.m
├── image
│ ├── aaa.jpg
│ ├── abc.mp4
│ ├── ic_circle@2x.png
│ ├── pause_nor@2x.png
│ └── play_nor@2x.png
└── main.m
├── SCN3DPlayerTests
├── Info.plist
└── SCN3DPlayerTests.m
└── SCN3DPlayerUITests
├── Info.plist
└── SCN3DPlayerUITests.m
/2017-06-22 17_47_06.gif:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/2017-06-22 17_47_06.gif
--------------------------------------------------------------------------------
/README.md:
--------------------------------------------------------------------------------
1 | # SCN3DPlayer
2 | 这是一个vr,全景播放器,支持,网络视频,本地视频
3 |
--------------------------------------------------------------------------------
/SCN3DPlayer.xcodeproj/project.xcworkspace/contents.xcworkspacedata:
--------------------------------------------------------------------------------
1 |
2 |
4 |
6 |
7 |
8 |
--------------------------------------------------------------------------------
/SCN3DPlayer.xcodeproj/project.xcworkspace/xcuserdata/taiyoshimichi.xcuserdatad/UserInterfaceState.xcuserstate:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer.xcodeproj/project.xcworkspace/xcuserdata/taiyoshimichi.xcuserdatad/UserInterfaceState.xcuserstate
--------------------------------------------------------------------------------
/SCN3DPlayer.xcodeproj/xcuserdata/taiyoshimichi.xcuserdatad/xcdebugger/Breakpoints_v2.xcbkptlist:
--------------------------------------------------------------------------------
1 |
2 |
5 |
6 |
8 |
20 |
21 |
22 |
24 |
36 |
37 |
38 |
40 |
52 |
53 |
54 |
56 |
68 |
69 |
70 |
72 |
84 |
85 |
86 |
88 |
100 |
101 |
102 |
104 |
116 |
117 |
118 |
120 |
132 |
133 |
134 |
136 |
148 |
149 |
150 |
152 |
164 |
165 |
166 |
168 |
180 |
181 |
182 |
184 |
196 |
197 |
198 |
200 |
212 |
213 |
214 |
216 |
228 |
229 |
230 |
232 |
244 |
245 |
246 |
248 |
260 |
261 |
262 |
264 |
270 |
271 |
272 |
274 |
286 |
287 |
288 |
290 |
302 |
303 |
304 |
306 |
318 |
319 |
320 |
322 |
334 |
335 |
336 |
338 |
350 |
351 |
352 |
353 |
354 |
--------------------------------------------------------------------------------
/SCN3DPlayer.xcodeproj/xcuserdata/taiyoshimichi.xcuserdatad/xcschemes/SCN3DPlayer.xcscheme:
--------------------------------------------------------------------------------
1 |
2 |
5 |
8 |
9 |
15 |
21 |
22 |
23 |
24 |
25 |
30 |
31 |
33 |
39 |
40 |
41 |
43 |
49 |
50 |
51 |
52 |
53 |
59 |
60 |
61 |
62 |
63 |
64 |
74 |
76 |
82 |
83 |
84 |
85 |
86 |
87 |
93 |
95 |
101 |
102 |
103 |
104 |
106 |
107 |
110 |
111 |
112 |
--------------------------------------------------------------------------------
/SCN3DPlayer.xcodeproj/xcuserdata/taiyoshimichi.xcuserdatad/xcschemes/xcschememanagement.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | SchemeUserState
6 |
7 | SCN3DPlayer.xcscheme
8 |
9 | orderHint
10 | 0
11 |
12 |
13 | SuppressBuildableAutocreation
14 |
15 | 7C44295F1DD5C9CB004BDAF2
16 |
17 | primary
18 |
19 |
20 | 7C4429781DD5C9CD004BDAF2
21 |
22 | primary
23 |
24 |
25 | 7C4429831DD5C9CD004BDAF2
26 |
27 | primary
28 |
29 |
30 |
31 |
32 |
33 |
--------------------------------------------------------------------------------
/SCN3DPlayer/AppDelegate.h:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.h
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface AppDelegate : UIResponder
12 |
13 | @property (strong, nonatomic) UIWindow *window;
14 |
15 |
16 | @end
17 |
18 |
--------------------------------------------------------------------------------
/SCN3DPlayer/AppDelegate.m:
--------------------------------------------------------------------------------
1 | //
2 | // AppDelegate.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import "AppDelegate.h"
10 | #import "ViewController.h"
11 |
12 | @interface AppDelegate ()
13 |
14 | @end
15 |
16 | @implementation AppDelegate
17 |
18 |
19 | - (BOOL)application:(UIApplication *)application didFinishLaunchingWithOptions:(NSDictionary *)launchOptions {
20 | // Override point for customization after application launch.
21 | return YES;
22 | }
23 |
24 |
25 | - (void)applicationWillResignActive:(UIApplication *)application {
26 | // 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.
27 | // Use this method to pause ongoing tasks, disable timers, and invalidate graphics rendering callbacks. Games should use this method to pause the game.
28 | }
29 |
30 |
31 | - (void)applicationDidEnterBackground:(UIApplication *)application {
32 | // 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.
33 | // If your application supports background execution, this method is called instead of applicationWillTerminate: when the user quits.
34 | }
35 |
36 |
37 | - (void)applicationWillEnterForeground:(UIApplication *)application {
38 | // Called as part of the transition from the background to the active state; here you can undo many of the changes made on entering the background.
39 | }
40 |
41 |
42 | - (void)applicationDidBecomeActive:(UIApplication *)application {
43 | // 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.
44 | }
45 |
46 |
47 | - (void)applicationWillTerminate:(UIApplication *)application {
48 | // Called when the application is about to terminate. Save data if appropriate. See also applicationDidEnterBackground:.
49 | }
50 |
51 |
52 | @end
53 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Assets.xcassets/AppIcon.appiconset/Contents.json:
--------------------------------------------------------------------------------
1 | {
2 | "images" : [
3 | {
4 | "idiom" : "iphone",
5 | "size" : "29x29",
6 | "scale" : "2x"
7 | },
8 | {
9 | "idiom" : "iphone",
10 | "size" : "29x29",
11 | "scale" : "3x"
12 | },
13 | {
14 | "idiom" : "iphone",
15 | "size" : "40x40",
16 | "scale" : "2x"
17 | },
18 | {
19 | "idiom" : "iphone",
20 | "size" : "40x40",
21 | "scale" : "3x"
22 | },
23 | {
24 | "idiom" : "iphone",
25 | "size" : "60x60",
26 | "scale" : "2x"
27 | },
28 | {
29 | "idiom" : "iphone",
30 | "size" : "60x60",
31 | "scale" : "3x"
32 | },
33 | {
34 | "idiom" : "ipad",
35 | "size" : "29x29",
36 | "scale" : "1x"
37 | },
38 | {
39 | "idiom" : "ipad",
40 | "size" : "29x29",
41 | "scale" : "2x"
42 | },
43 | {
44 | "idiom" : "ipad",
45 | "size" : "40x40",
46 | "scale" : "1x"
47 | },
48 | {
49 | "idiom" : "ipad",
50 | "size" : "40x40",
51 | "scale" : "2x"
52 | },
53 | {
54 | "idiom" : "ipad",
55 | "size" : "76x76",
56 | "scale" : "1x"
57 | },
58 | {
59 | "idiom" : "ipad",
60 | "size" : "76x76",
61 | "scale" : "2x"
62 | }
63 | ],
64 | "info" : {
65 | "version" : 1,
66 | "author" : "xcode"
67 | }
68 | }
--------------------------------------------------------------------------------
/SCN3DPlayer/Base.lproj/LaunchScreen.storyboard:
--------------------------------------------------------------------------------
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 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Base.lproj/Main.storyboard:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 |
6 |
7 |
8 |
9 |
10 |
11 |
12 |
13 |
14 |
15 |
16 |
17 |
18 |
19 |
20 |
21 |
22 |
23 |
24 |
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 |
70 |
79 |
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 |
145 |
146 |
147 |
--------------------------------------------------------------------------------
/SCN3DPlayer/HelloViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // HelloViewController.h
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface HelloViewController : UIViewController
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/SCN3DPlayer/HelloViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // HelloViewController.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import "HelloViewController.h"
10 | #import "SCN3DPlayerView.h"
11 | #import "SCN3DVideoAdatper.h"
12 | #import "HelloViewController.h"
13 | #import "Masonry.h"
14 |
15 | @interface HelloViewController (){
16 |
17 |
18 | }
19 | @property (nonatomic,strong)SCN3DPlayerView *scn3DPlayerView;
20 | @property (nonatomic,strong)SCN3DVideoAdatper *scn3dVideo;
21 | //@property (strong, nonatomic) IBOutlet UIButton *playAndStop;
22 | //@property (strong, nonatomic) IBOutlet UILabel *curTimeLabel;
23 | //@property (strong, nonatomic) IBOutlet UILabel *allTimeLabel;
24 | //@property (strong, nonatomic) IBOutlet UIProgressView *progressView;
25 | //@property (strong, nonatomic) IBOutlet UISlider *timeSlider;
26 | //@property (strong, nonatomic) IBOutlet UIView *upView;
27 | //@property (strong, nonatomic) IBOutlet UIView *videoView;
28 |
29 | @property (strong, nonatomic) UIButton *playAndStop;
30 | @property (strong, nonatomic) UILabel *curTimeLabel;
31 | @property (strong, nonatomic) UILabel *allTimeLabel;
32 | @property (strong, nonatomic) UIProgressView *progressView;
33 | @property (strong, nonatomic) UISlider *timeSlider;
34 | @property (strong, nonatomic) UIView *upView;
35 | @property (strong, nonatomic) UIView *videoView;
36 |
37 | @property (nonatomic, assign) CGSize displaySize;
38 | @property (nonatomic, assign) float aspect;
39 |
40 | @end
41 |
42 |
43 | @implementation HelloViewController
44 |
45 | -(void)viewWillDisappear:(BOOL)animated{
46 | [self.scn3dVideo pause];
47 | [self.scn3dVideo removeDisplaylink];
48 | [self.scn3DPlayerView removeFromSuperview];
49 | self.scn3DPlayerView = nil;
50 |
51 | }
52 |
53 | -(void)viewWillAppear:(BOOL)animated{
54 | // self.scn3DPlayerView.frame = self.videoView.bounds;
55 |
56 | }
57 | -(void)viewDidAppear:(BOOL)animated{
58 | self.scn3DPlayerView.frame = self.view.frame;
59 |
60 |
61 |
62 |
63 |
64 | }
65 | - (void)viewDidLoad {
66 | [super viewDidLoad];
67 | self.view.backgroundColor = [UIColor whiteColor];
68 | // Do any additional setup after loading the view, typically from a nib.
69 |
70 | [self initSCN3DPlayerView];
71 | [self setSlider];
72 | [self initBtn];
73 | [self initVideo];
74 |
75 |
76 | }
77 |
78 | -(void)initSCN3DPlayerView{
79 | self.scn3DPlayerView = [[SCN3DPlayerView alloc]initWithFrame:self.view.frame];
80 | [self.view addSubview:self.scn3DPlayerView];
81 | [self.scn3DPlayerView setInteractiveMode:SCN3DInteractive_MotionAndTouch];//设置重力触摸模式
82 | // [self.scn3DPlayerView setVideoAspectRatio:2.0];//设置视频宽高比
83 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_Plane_Normal];//初始化设置普通模式
84 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:YES];//设置触摸开关
85 | [self.scn3DPlayerView setPinchScaleEnabled:YES];//设置允许缩放
86 | [self.scn3DPlayerView setMinScale:1 maxScale:2.0];//设置缩放比例范围
87 | [self.scn3DPlayerView setCurrentScale:1.0]; //设置当前缩放比例
88 |
89 |
90 | }
91 | -(void)setSlider{
92 | _upView = [[UIView alloc]init];
93 | [self.view addSubview:_upView];
94 | _upView.backgroundColor = [UIColor grayColor];
95 |
96 | _playAndStop = [[UIButton alloc]init];
97 |
98 | [self.upView addSubview:_playAndStop];
99 | [_playAndStop setImage:[UIImage imageNamed:@"play_nor"] forState:UIControlStateNormal];
100 | [_playAndStop setImage:[UIImage imageNamed:@"pause_nor"] forState:UIControlStateSelected];
101 | [_playAndStop addTarget:self action:@selector(playAndstopClick:) forControlEvents:UIControlEventTouchUpInside];
102 |
103 | _curTimeLabel =[[UILabel alloc]init];
104 | [self.upView addSubview:_curTimeLabel];
105 | _curTimeLabel.text = @"00:00:00";
106 | _curTimeLabel.font =[UIFont systemFontOfSize:13];
107 |
108 | _allTimeLabel = [[UILabel alloc]init];
109 | [self.upView addSubview:_allTimeLabel];
110 | _allTimeLabel.text = @"00:00:00";
111 | _allTimeLabel.font = [UIFont systemFontOfSize:13];
112 |
113 | _progressView = [[UIProgressView alloc]init];
114 | [self.upView addSubview:_progressView];
115 | _progressView.progress = 0.0 ;
116 |
117 | _timeSlider = [[UISlider alloc]init];
118 | [self.upView addSubview:_timeSlider];
119 | _timeSlider.value = 0;
120 | [_timeSlider addTarget:self action:@selector(timeSliderValueChanged:) forControlEvents: UIControlEventValueChanged];
121 |
122 |
123 |
124 | __weak typeof(self) weakSelf = self;
125 |
126 | [self.upView mas_makeConstraints:^(MASConstraintMaker *make) {
127 | make.leading.and.trailing.equalTo(weakSelf.view).offset(0);
128 | make.bottom.equalTo(weakSelf.view).offset(0);
129 | make.height.equalTo(@60);
130 | }];
131 |
132 | [self.playAndStop mas_makeConstraints:^(MASConstraintMaker *make) {
133 | make.leading.equalTo(weakSelf.upView);
134 | make.centerY.equalTo(weakSelf.upView);
135 | make.height.and.width.equalTo(@40);
136 |
137 | }];
138 |
139 | [self.curTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
140 | make.leading.equalTo(weakSelf.playAndStop.mas_trailing).offset(0);
141 | make.centerY.equalTo(weakSelf.upView);
142 | make.width.equalTo (@60);
143 |
144 | }];
145 | [self.allTimeLabel mas_makeConstraints:^(MASConstraintMaker *make) {
146 | make.trailing.equalTo(weakSelf.upView.mas_trailing).offset(-5);
147 | make.centerY.equalTo(weakSelf.upView);
148 | make.width.equalTo (@60);
149 |
150 | }];
151 |
152 | [self.timeSlider mas_makeConstraints:^(MASConstraintMaker *make) {
153 | make.leading.equalTo(weakSelf.curTimeLabel.mas_trailing).offset(0);
154 | make.trailing.equalTo(weakSelf.allTimeLabel.mas_leading).offset(-8);
155 | make.centerY.equalTo(weakSelf.upView);
156 | }];
157 |
158 | [self.progressView mas_makeConstraints:^(MASConstraintMaker *make) {
159 | make.leading.equalTo(weakSelf.curTimeLabel.mas_trailing).offset(0);
160 | make.trailing.equalTo(weakSelf.allTimeLabel.mas_leading).offset(-8);
161 | make.centerY.equalTo(weakSelf.upView);
162 | }];
163 |
164 |
165 |
166 |
167 |
168 | [self.timeSlider setThumbImage:[UIImage imageNamed:@"ic_circle@2x"] forState:UIControlStateNormal];
169 | [self.timeSlider setThumbImage:[UIImage imageNamed:@"ic_circle@2x"] forState:UIControlStateHighlighted];
170 | UIGraphicsBeginImageContextWithOptions((CGSize){ 1, 1 }, NO, 0.0f);
171 | UIImage *transparentImage = UIGraphicsGetImageFromCurrentImageContext();
172 | UIGraphicsEndImageContext();
173 | [self.timeSlider setMinimumTrackImage:transparentImage forState:UIControlStateNormal];
174 | [self.timeSlider setMaximumTrackImage:transparentImage forState:UIControlStateNormal];
175 | }
176 |
177 | -(void)initBtn{
178 | UIButton * btn0 = [[UIButton alloc]initWithFrame:CGRectMake(100, 50, 70, 40)];
179 | [btn0 setTitle:@"正常" forState:UIControlStateNormal];
180 | [btn0 setBackgroundColor:[UIColor blueColor]];
181 | [self.view addSubview: btn0];
182 | btn0.alpha = 0.5;
183 | btn0.tag = SCN3DDisplayMode_Plane_Normal;
184 | [btn0 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
185 |
186 |
187 |
188 | UIButton * btn = [[UIButton alloc]initWithFrame:CGRectMake(100, 100, 70, 40)];
189 | [btn setTitle:@"平面180" forState:UIControlStateNormal];
190 | [btn setBackgroundColor:[UIColor blueColor]];
191 | [self.view addSubview: btn];
192 | btn.alpha = 0.5;
193 | btn.tag = SCN3DDisplayMode_Plane_Slide;
194 | [btn addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
195 |
196 |
197 |
198 | UIButton * btn2 = [[UIButton alloc]initWithFrame:CGRectMake(100, 150, 70, 40)];
199 | [btn2 setTitle:@"圆柱" forState:UIControlStateNormal];
200 | [btn2 setBackgroundColor:[UIColor blueColor]];
201 | [self.view addSubview: btn2];
202 | btn2.alpha = 0.5;
203 | btn2.tag = SCN3DDisplayMode_Tube;
204 | [btn2 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
205 |
206 |
207 |
208 | UIButton * btn3 = [[UIButton alloc]initWithFrame:CGRectMake(100, 200, 70, 40)];
209 | [btn3 setTitle:@"圆" forState:UIControlStateNormal];
210 | [btn3 setBackgroundColor:[UIColor blueColor]];
211 | [self.view addSubview: btn3];
212 | btn3.alpha = 0.5;
213 | btn3.tag = SCN3DDisplayMode_Sphere;
214 | [btn3 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
215 |
216 |
217 | UIButton * btn4 = [[UIButton alloc]initWithFrame:CGRectMake(100, 250, 70, 40)];
218 | [btn4 setTitle:@"全景" forState:UIControlStateNormal];
219 | [btn4 setBackgroundColor:[UIColor blueColor]];
220 | [self.view addSubview: btn4];
221 | btn4.alpha = 0.5;
222 | btn4.tag = SCN3DDisplayMode_VR360;
223 | [btn4 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
224 |
225 |
226 | UIButton * btn5 = [[UIButton alloc]initWithFrame:CGRectMake(100, 300, 70, 40)];
227 | [btn5 setTitle:@"VR" forState:UIControlStateNormal];
228 | [btn5 setBackgroundColor:[UIColor blueColor]];
229 | [self.view addSubview: btn5];
230 | btn5.alpha = 0.5;
231 | btn5.tag = SCN3DDisplayMode_VRGlass;
232 | [btn5 addTarget:self action:@selector(btnClick:) forControlEvents:UIControlEventTouchUpInside];
233 |
234 |
235 |
236 | UIButton * btn6 = [[UIButton alloc]initWithFrame:CGRectMake(10, 10, 50, 50)];
237 | [btn6 setTitle:@"返回" forState:UIControlStateNormal];
238 | [btn6 setBackgroundColor:[UIColor blueColor]];
239 | [self.view addSubview: btn6];
240 | btn6.alpha = 0.5;
241 | [btn6 addTarget:self action:@selector(backClick:) forControlEvents:UIControlEventTouchUpInside];
242 |
243 | UIButton * btn7 = [[UIButton alloc]initWithFrame:CGRectMake(80, 10, 50, 50)];
244 | [btn7 setTitle:@"+" forState:UIControlStateNormal];
245 | [btn7 setBackgroundColor:[UIColor blueColor]];
246 | [self.view addSubview: btn7];
247 | btn7.alpha = 0.5;
248 | [btn7 addTarget:self action:@selector(addvoluem:) forControlEvents:UIControlEventTouchUpInside];
249 | UIButton * btn8 = [[UIButton alloc]initWithFrame:CGRectMake(150, 10, 50, 50)];
250 | [btn8 setTitle:@"-" forState:UIControlStateNormal];
251 | [btn8 setBackgroundColor:[UIColor blueColor]];
252 | [self.view addSubview: btn8];
253 | btn8.alpha = 0.5;
254 |
255 | [btn8 addTarget:self action:@selector(subvoluem:) forControlEvents:UIControlEventTouchUpInside];
256 |
257 | UITapGestureRecognizer * tap = [[UITapGestureRecognizer alloc]initWithTarget:self action:@selector(tapClick)];
258 | [self.view addGestureRecognizer:tap];
259 |
260 |
261 | }
262 |
263 | -(void)btnClick:(UIButton*)btn{
264 |
265 | if (btn.tag == SCN3DDisplayMode_Plane_Normal) {
266 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_Plane_Normal];
267 |
268 | }else if (btn.tag == SCN3DDisplayMode_Plane_Slide) {
269 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_Plane_Slide];
270 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:NO];//设置水平垂直是否启用
271 | [self.scn3DPlayerView setPinchScaleEnabled:YES];
272 |
273 |
274 |
275 | }else if (btn.tag == SCN3DDisplayMode_Tube){
276 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_Tube];
277 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:YES];
278 | [self.scn3DPlayerView setVerticalMinRotate:-60 maxRotate:60];
279 |
280 |
281 | }else if (btn.tag == SCN3DDisplayMode_Sphere){
282 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_Sphere];
283 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:YES];//设置水平垂直是否启用
284 |
285 | }else if (btn.tag == SCN3DDisplayMode_VR360){
286 |
287 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_VR360];
288 | [self.scn3DPlayerView setVerticalMinRotate:30 maxRotate:90];
289 | [self.scn3DPlayerView setCurrentRotateX:30 rotateY:0];
290 | self.scn3DPlayerView.cameraNode.position = SCNVector3Make(0, 0.1, 1.0);
291 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:YES];
292 | [self.scn3DPlayerView setGSensorMotionEnabled:YES];
293 | [self.scn3DPlayerView setPinchScaleEnabled:YES];
294 |
295 |
296 | }else if (btn.tag == SCN3DDisplayMode_VRGlass){
297 |
298 | [self.scn3DPlayerView setVideoDisplayMode:SCN3DDisplayMode_VRGlass];
299 | [self.scn3DPlayerView setHorizontalEnabled:YES verticalEnabled:YES];
300 | [self.scn3DPlayerView setGSensorMotionEnabled:YES];
301 | [self.scn3DPlayerView setPinchScaleEnabled:YES];
302 |
303 | }
304 |
305 |
306 | }
307 |
308 | -(void)tapClick{
309 | dispatch_async(dispatch_get_main_queue(), ^{
310 | [UIView animateWithDuration:0.3 animations:^{
311 | self.upView.alpha = 1.0;
312 | self.upView.alpha = 1.0;
313 | }];
314 |
315 | });
316 | dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(6 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
317 | [UIView animateWithDuration:1.0 animations:^{
318 | self.upView.alpha = 0.0;
319 | self.upView.alpha = 0.0;
320 | }];
321 |
322 | });
323 |
324 |
325 |
326 | }
327 | -(void)initVideo{
328 | self.scn3dVideo = [[SCN3DVideoAdatper alloc]init];
329 |
330 | NSString * urlString = [[NSBundle mainBundle]pathForResource:@"abc" ofType:@"mp4"];
331 | // NSString * urlString = @"http://cache.utovr.com/aa38e1ffef5d4b9baaf393777dbc9342/L2_gx91akbix0qkiacw.mp4";
332 |
333 |
334 | NSURL *videoURL;
335 |
336 | if ([self checkPathIsHTTPURL:urlString]) {
337 | videoURL = [NSURL URLWithString:urlString]; //网络视频
338 |
339 | }
340 | else {
341 | videoURL = [NSURL fileURLWithPath:urlString];//本地视频
342 |
343 | }
344 | //播放方法一
345 | [self.scn3dVideo setURL:videoURL];
346 |
347 | //播放方法二
348 | // AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:url];
349 | // [self.scn3dVideo setPlayerItem:playerItem];
350 |
351 | //方法三
352 | // AVAsset * asset = [AVAsset assetWithURL:url];
353 | // [self.scn3dVideo setAsset:asset];
354 |
355 |
356 | self.scn3dVideo.delegate = self;
357 |
358 | }
359 |
360 | - (void)didReceiveMemoryWarning {
361 | [super didReceiveMemoryWarning];
362 | // Dispose of any resources that can be recreated.
363 | }
364 |
365 |
366 |
367 |
368 |
369 | - (void)videoPlayerIsReadyToPlayVideo:(SCN3DVideoAdatper *)videoAdatper{
370 | NSLog(@"准备播放====================");
371 | [self.scn3dVideo addDisplaylink];
372 | [self.scn3dVideo play];
373 | self.playAndStop.selected = YES;
374 | int totalTime = CMTimeGetSeconds(videoAdatper.playerItem.duration);
375 | self.timeSlider.maximumValue = totalTime;
376 | self.allTimeLabel.text = [self getVideoTimeString:totalTime];
377 | NSLog(@"time =========%d",totalTime);
378 |
379 | }
380 |
381 | - (void)videoPlayerDidReachEnd:(SCN3DVideoAdatper *)videoAdatper{
382 | NSLog(@"播放结束 ==============");
383 | [self.scn3dVideo pause];
384 |
385 |
386 | }
387 |
388 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper timeDidChange:(CMTime)cmTime{
389 |
390 | int curTime = CMTimeGetSeconds(cmTime);
391 | self.timeSlider.value = curTime;
392 | self.curTimeLabel.text = [self getVideoTimeString:curTime];
393 | }
394 |
395 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper loadedTimeRangeDidChange:(float)duration{
396 |
397 | // 视频缓冲长度
398 | int totalTime = CMTimeGetSeconds(videoAdatper.playerItem.duration);
399 | if (totalTime != 0) {
400 | self.progressView.progress = duration / totalTime;
401 |
402 |
403 | }
404 | }
405 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper didFailWithError:(NSError *)error{
406 | NSLog(@"error====================%@",error);
407 | }
408 |
409 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper displaylinkCallbackImage:(UIImage *)videoImage{
410 | //获取视频的每一帧
411 | [self.scn3DPlayerView setFramesPerVideoImage:videoImage];
412 | _aspect = videoImage.size.width/videoImage.size.height;
413 |
414 |
415 | }
416 |
417 | - (NSString *)getVideoTimeString:(int)time {
418 | int hou = time / 3600;
419 | int min = (time - hou * 60) / 60;
420 | int sec = time - hou * 3600 - min * 60;
421 | return [NSString stringWithFormat:@"%02d:%02d:%02d", hou, min, sec];
422 | }
423 |
424 | //支持的方向
425 | -(UIInterfaceOrientationMask)supportedInterfaceOrientations{
426 |
427 | return UIInterfaceOrientationMaskAll;
428 |
429 | }
430 |
431 | //是否可以旋转
432 | -(BOOL)shouldAutorotate{
433 |
434 | return YES;
435 | }
436 | // 横竖屏适配.
437 | - (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration{
438 |
439 | [self relayout];
440 | }
441 |
442 | - (void)relayout
443 | {
444 | if(self.view.frame.size.width>self.view.frame.size.height) {
445 | self.scn3DPlayerView .frame = self.view.frame;
446 |
447 | } else {
448 | self.scn3DPlayerView.frame = self.view.frame;
449 | }
450 | }
451 |
452 | - (BOOL)checkPathIsHTTPURL:(NSString *)path {
453 | NSString *head = [path substringWithRange:NSMakeRange(0, 4)];
454 | NSStringCompareOptions options = NSCaseInsensitiveSearch | NSNumericSearch;
455 | if ([head compare:@"http" options:options] == NSOrderedSame) {
456 | return YES;
457 | }
458 | return NO;
459 | }
460 | - (void)playAndstopClick:(UIButton *)sender {
461 | if (self.scn3dVideo.isPlaying) {
462 | [self.scn3dVideo pause];
463 | self.playAndStop.selected = NO;
464 | }else{
465 | [self.scn3dVideo play];
466 | self.playAndStop.selected = YES;
467 | }
468 | }
469 |
470 | - (void)timeSliderValueChanged:(UISlider*)sender { // 滑动播放进度
471 | float seekTime = sender.value;
472 | if (self.scn3dVideo.isPlaying) {
473 | [self.scn3dVideo pause];
474 | }
475 | if (self.playAndStop.selected == YES) {
476 | [self.scn3dVideo play];
477 | }
478 |
479 | [self.scn3dVideo seekToTime:seekTime completion:nil];
480 | }
481 | - (void)backClick:(UIButton *)sender {
482 |
483 | [self dismissViewControllerAnimated:YES completion:nil];
484 | }
485 |
486 | -(void)subvoluem:(UIButton *)sender{
487 |
488 | [self.scn3dVideo fadeOutVolume];
489 | }
490 | -(void)addvoluem:(UIButton *)sender{
491 |
492 | [self.scn3dVideo fadeInVolume];
493 | }
494 |
495 | @end
496 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | APPL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 | LSRequiresIPhoneOS
22 |
23 | UILaunchStoryboardName
24 | LaunchScreen
25 | UIMainStoryboardFile
26 | Main
27 | UIRequiredDeviceCapabilities
28 |
29 | armv7
30 |
31 | UISupportedInterfaceOrientations
32 |
33 | UIInterfaceOrientationPortrait
34 | UIInterfaceOrientationLandscapeLeft
35 | UIInterfaceOrientationLandscapeRight
36 |
37 | UISupportedInterfaceOrientations~ipad
38 |
39 | UIInterfaceOrientationPortrait
40 | UIInterfaceOrientationPortraitUpsideDown
41 | UIInterfaceOrientationLandscapeLeft
42 | UIInterfaceOrientationLandscapeRight
43 |
44 | NSAppTransportSecurity
45 |
46 | NSAllowsArbitraryLoads
47 |
48 |
49 |
50 |
51 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASCompositeConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | /**
13 | * A group of MASConstraint objects
14 | */
15 | @interface MASCompositeConstraint : MASConstraint
16 |
17 | /**
18 | * Creates a composite with a predefined array of children
19 | *
20 | * @param children child MASConstraints
21 | *
22 | * @return a composite constraint
23 | */
24 | - (id)initWithChildren:(NSArray *)children;
25 |
26 | @end
27 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASCompositeConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASCompositeConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASCompositeConstraint.h"
10 | #import "MASConstraint+Private.h"
11 |
12 | @interface MASCompositeConstraint ()
13 |
14 | @property (nonatomic, strong) id mas_key;
15 | @property (nonatomic, strong) NSMutableArray *childConstraints;
16 |
17 | @end
18 |
19 | @implementation MASCompositeConstraint
20 |
21 | - (id)initWithChildren:(NSArray *)children {
22 | self = [super init];
23 | if (!self) return nil;
24 |
25 | _childConstraints = [children mutableCopy];
26 | for (MASConstraint *constraint in _childConstraints) {
27 | constraint.delegate = self;
28 | }
29 |
30 | return self;
31 | }
32 |
33 | #pragma mark - MASConstraintDelegate
34 |
35 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
36 | NSUInteger index = [self.childConstraints indexOfObject:constraint];
37 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
38 | [self.childConstraints replaceObjectAtIndex:index withObject:replacementConstraint];
39 | }
40 |
41 | - (MASConstraint *)constraint:(MASConstraint __unused *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
42 | id strongDelegate = self.delegate;
43 | MASConstraint *newConstraint = [strongDelegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
44 | newConstraint.delegate = self;
45 | [self.childConstraints addObject:newConstraint];
46 | return newConstraint;
47 | }
48 |
49 | #pragma mark - NSLayoutConstraint multiplier proxies
50 |
51 | - (MASConstraint * (^)(CGFloat))multipliedBy {
52 | return ^id(CGFloat multiplier) {
53 | for (MASConstraint *constraint in self.childConstraints) {
54 | constraint.multipliedBy(multiplier);
55 | }
56 | return self;
57 | };
58 | }
59 |
60 | - (MASConstraint * (^)(CGFloat))dividedBy {
61 | return ^id(CGFloat divider) {
62 | for (MASConstraint *constraint in self.childConstraints) {
63 | constraint.dividedBy(divider);
64 | }
65 | return self;
66 | };
67 | }
68 |
69 | #pragma mark - MASLayoutPriority proxy
70 |
71 | - (MASConstraint * (^)(MASLayoutPriority))priority {
72 | return ^id(MASLayoutPriority priority) {
73 | for (MASConstraint *constraint in self.childConstraints) {
74 | constraint.priority(priority);
75 | }
76 | return self;
77 | };
78 | }
79 |
80 | #pragma mark - NSLayoutRelation proxy
81 |
82 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
83 | return ^id(id attr, NSLayoutRelation relation) {
84 | for (MASConstraint *constraint in self.childConstraints.copy) {
85 | constraint.equalToWithRelation(attr, relation);
86 | }
87 | return self;
88 | };
89 | }
90 |
91 | #pragma mark - attribute chaining
92 |
93 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
94 | [self constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
95 | return self;
96 | }
97 |
98 | #pragma mark - Animator proxy
99 |
100 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
101 |
102 | - (MASConstraint *)animator {
103 | for (MASConstraint *constraint in self.childConstraints) {
104 | [constraint animator];
105 | }
106 | return self;
107 | }
108 |
109 | #endif
110 |
111 | #pragma mark - debug helpers
112 |
113 | - (MASConstraint * (^)(id))key {
114 | return ^id(id key) {
115 | self.mas_key = key;
116 | int i = 0;
117 | for (MASConstraint *constraint in self.childConstraints) {
118 | constraint.key([NSString stringWithFormat:@"%@[%d]", key, i++]);
119 | }
120 | return self;
121 | };
122 | }
123 |
124 | #pragma mark - NSLayoutConstraint constant setters
125 |
126 | - (void)setInsets:(MASEdgeInsets)insets {
127 | for (MASConstraint *constraint in self.childConstraints) {
128 | constraint.insets = insets;
129 | }
130 | }
131 |
132 | - (void)setOffset:(CGFloat)offset {
133 | for (MASConstraint *constraint in self.childConstraints) {
134 | constraint.offset = offset;
135 | }
136 | }
137 |
138 | - (void)setSizeOffset:(CGSize)sizeOffset {
139 | for (MASConstraint *constraint in self.childConstraints) {
140 | constraint.sizeOffset = sizeOffset;
141 | }
142 | }
143 |
144 | - (void)setCenterOffset:(CGPoint)centerOffset {
145 | for (MASConstraint *constraint in self.childConstraints) {
146 | constraint.centerOffset = centerOffset;
147 | }
148 | }
149 |
150 | #pragma mark - MASConstraint
151 |
152 | - (void)activate {
153 | for (MASConstraint *constraint in self.childConstraints) {
154 | [constraint activate];
155 | }
156 | }
157 |
158 | - (void)deactivate {
159 | for (MASConstraint *constraint in self.childConstraints) {
160 | [constraint deactivate];
161 | }
162 | }
163 |
164 | - (void)install {
165 | for (MASConstraint *constraint in self.childConstraints) {
166 | constraint.updateExisting = self.updateExisting;
167 | [constraint install];
168 | }
169 | }
170 |
171 | - (void)uninstall {
172 | for (MASConstraint *constraint in self.childConstraints) {
173 | [constraint uninstall];
174 | }
175 | }
176 |
177 | @end
178 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASConstraint+Private.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint+Private.h
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 29/04/14.
6 | // Copyright (c) 2014 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 |
11 | @protocol MASConstraintDelegate;
12 |
13 |
14 | @interface MASConstraint ()
15 |
16 | /**
17 | * Whether or not to check for an existing constraint instead of adding constraint
18 | */
19 | @property (nonatomic, assign) BOOL updateExisting;
20 |
21 | /**
22 | * Usually MASConstraintMaker but could be a parent MASConstraint
23 | */
24 | @property (nonatomic, weak) id delegate;
25 |
26 | /**
27 | * Based on a provided value type, is equal to calling:
28 | * NSNumber - setOffset:
29 | * NSValue with CGPoint - setPointOffset:
30 | * NSValue with CGSize - setSizeOffset:
31 | * NSValue with MASEdgeInsets - setInsets:
32 | */
33 | - (void)setLayoutConstantWithValue:(NSValue *)value;
34 |
35 | @end
36 |
37 |
38 | @interface MASConstraint (Abstract)
39 |
40 | /**
41 | * Sets the constraint relation to given NSLayoutRelation
42 | * returns a block which accepts one of the following:
43 | * MASViewAttribute, UIView, NSValue, NSArray
44 | * see readme for more details.
45 | */
46 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation;
47 |
48 | /**
49 | * Override to set a custom chaining behaviour
50 | */
51 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
52 |
53 | @end
54 |
55 |
56 | @protocol MASConstraintDelegate
57 |
58 | /**
59 | * Notifies the delegate when the constraint needs to be replaced with another constraint. For example
60 | * A MASViewConstraint may turn into a MASCompositeConstraint when an array is passed to one of the equality blocks
61 | */
62 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint;
63 |
64 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute;
65 |
66 | @end
67 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * Enables Constraints to be created with chainable syntax
13 | * Constraint can represent single NSLayoutConstraint (MASViewConstraint)
14 | * or a group of NSLayoutConstraints (MASComposisteConstraint)
15 | */
16 | @interface MASConstraint : NSObject
17 |
18 | // Chaining Support
19 |
20 | /**
21 | * Modifies the NSLayoutConstraint constant,
22 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
23 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
24 | */
25 | - (MASConstraint * (^)(MASEdgeInsets insets))insets;
26 |
27 | /**
28 | * Modifies the NSLayoutConstraint constant,
29 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
30 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
31 | */
32 | - (MASConstraint * (^)(CGSize offset))sizeOffset;
33 |
34 | /**
35 | * Modifies the NSLayoutConstraint constant,
36 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
37 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
38 | */
39 | - (MASConstraint * (^)(CGPoint offset))centerOffset;
40 |
41 | /**
42 | * Modifies the NSLayoutConstraint constant
43 | */
44 | - (MASConstraint * (^)(CGFloat offset))offset;
45 |
46 | /**
47 | * Modifies the NSLayoutConstraint constant based on a value type
48 | */
49 | - (MASConstraint * (^)(NSValue *value))valueOffset;
50 |
51 | /**
52 | * Sets the NSLayoutConstraint multiplier property
53 | */
54 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy;
55 |
56 | /**
57 | * Sets the NSLayoutConstraint multiplier to 1.0/dividedBy
58 | */
59 | - (MASConstraint * (^)(CGFloat divider))dividedBy;
60 |
61 | /**
62 | * Sets the NSLayoutConstraint priority to a float or MASLayoutPriority
63 | */
64 | - (MASConstraint * (^)(MASLayoutPriority priority))priority;
65 |
66 | /**
67 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityLow
68 | */
69 | - (MASConstraint * (^)())priorityLow;
70 |
71 | /**
72 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityMedium
73 | */
74 | - (MASConstraint * (^)())priorityMedium;
75 |
76 | /**
77 | * Sets the NSLayoutConstraint priority to MASLayoutPriorityHigh
78 | */
79 | - (MASConstraint * (^)())priorityHigh;
80 |
81 | /**
82 | * Sets the constraint relation to NSLayoutRelationEqual
83 | * returns a block which accepts one of the following:
84 | * MASViewAttribute, UIView, NSValue, NSArray
85 | * see readme for more details.
86 | */
87 | - (MASConstraint * (^)(id attr))equalTo;
88 |
89 | /**
90 | * Sets the constraint relation to NSLayoutRelationGreaterThanOrEqual
91 | * returns a block which accepts one of the following:
92 | * MASViewAttribute, UIView, NSValue, NSArray
93 | * see readme for more details.
94 | */
95 | - (MASConstraint * (^)(id attr))greaterThanOrEqualTo;
96 |
97 | /**
98 | * Sets the constraint relation to NSLayoutRelationLessThanOrEqual
99 | * returns a block which accepts one of the following:
100 | * MASViewAttribute, UIView, NSValue, NSArray
101 | * see readme for more details.
102 | */
103 | - (MASConstraint * (^)(id attr))lessThanOrEqualTo;
104 |
105 | /**
106 | * Optional semantic property which has no effect but improves the readability of constraint
107 | */
108 | - (MASConstraint *)with;
109 |
110 | /**
111 | * Optional semantic property which has no effect but improves the readability of constraint
112 | */
113 | - (MASConstraint *)and;
114 |
115 | /**
116 | * Creates a new MASCompositeConstraint with the called attribute and reciever
117 | */
118 | - (MASConstraint *)left;
119 | - (MASConstraint *)top;
120 | - (MASConstraint *)right;
121 | - (MASConstraint *)bottom;
122 | - (MASConstraint *)leading;
123 | - (MASConstraint *)trailing;
124 | - (MASConstraint *)width;
125 | - (MASConstraint *)height;
126 | - (MASConstraint *)centerX;
127 | - (MASConstraint *)centerY;
128 | - (MASConstraint *)baseline;
129 |
130 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
131 |
132 | - (MASConstraint *)firstBaseline;
133 | - (MASConstraint *)lastBaseline;
134 |
135 | #endif
136 |
137 | #if TARGET_OS_IPHONE || TARGET_OS_TV
138 |
139 | - (MASConstraint *)leftMargin;
140 | - (MASConstraint *)rightMargin;
141 | - (MASConstraint *)topMargin;
142 | - (MASConstraint *)bottomMargin;
143 | - (MASConstraint *)leadingMargin;
144 | - (MASConstraint *)trailingMargin;
145 | - (MASConstraint *)centerXWithinMargins;
146 | - (MASConstraint *)centerYWithinMargins;
147 |
148 | #endif
149 |
150 |
151 | /**
152 | * Sets the constraint debug name
153 | */
154 | - (MASConstraint * (^)(id key))key;
155 |
156 | // NSLayoutConstraint constant Setters
157 | // for use outside of mas_updateConstraints/mas_makeConstraints blocks
158 |
159 | /**
160 | * Modifies the NSLayoutConstraint constant,
161 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
162 | * NSLayoutAttributeTop, NSLayoutAttributeLeft, NSLayoutAttributeBottom, NSLayoutAttributeRight
163 | */
164 | - (void)setInsets:(MASEdgeInsets)insets;
165 |
166 | /**
167 | * Modifies the NSLayoutConstraint constant,
168 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
169 | * NSLayoutAttributeWidth, NSLayoutAttributeHeight
170 | */
171 | - (void)setSizeOffset:(CGSize)sizeOffset;
172 |
173 | /**
174 | * Modifies the NSLayoutConstraint constant,
175 | * only affects MASConstraints in which the first item's NSLayoutAttribute is one of the following
176 | * NSLayoutAttributeCenterX, NSLayoutAttributeCenterY
177 | */
178 | - (void)setCenterOffset:(CGPoint)centerOffset;
179 |
180 | /**
181 | * Modifies the NSLayoutConstraint constant
182 | */
183 | - (void)setOffset:(CGFloat)offset;
184 |
185 |
186 | // NSLayoutConstraint Installation support
187 |
188 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
189 | /**
190 | * Whether or not to go through the animator proxy when modifying the constraint
191 | */
192 | @property (nonatomic, copy, readonly) MASConstraint *animator;
193 | #endif
194 |
195 | /**
196 | * Activates an NSLayoutConstraint if it's supported by an OS.
197 | * Invokes install otherwise.
198 | */
199 | - (void)activate;
200 |
201 | /**
202 | * Deactivates previously installed/activated NSLayoutConstraint.
203 | */
204 | - (void)deactivate;
205 |
206 | /**
207 | * Creates a NSLayoutConstraint and adds it to the appropriate view.
208 | */
209 | - (void)install;
210 |
211 | /**
212 | * Removes previously installed NSLayoutConstraint
213 | */
214 | - (void)uninstall;
215 |
216 | @end
217 |
218 |
219 | /**
220 | * Convenience auto-boxing macros for MASConstraint methods.
221 | *
222 | * Defining MAS_SHORTHAND_GLOBALS will turn on auto-boxing for default syntax.
223 | * A potential drawback of this is that the unprefixed macros will appear in global scope.
224 | */
225 | #define mas_equalTo(...) equalTo(MASBoxValue((__VA_ARGS__)))
226 | #define mas_greaterThanOrEqualTo(...) greaterThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
227 | #define mas_lessThanOrEqualTo(...) lessThanOrEqualTo(MASBoxValue((__VA_ARGS__)))
228 |
229 | #define mas_offset(...) valueOffset(MASBoxValue((__VA_ARGS__)))
230 |
231 |
232 | #ifdef MAS_SHORTHAND_GLOBALS
233 |
234 | #define equalTo(...) mas_equalTo(__VA_ARGS__)
235 | #define greaterThanOrEqualTo(...) mas_greaterThanOrEqualTo(__VA_ARGS__)
236 | #define lessThanOrEqualTo(...) mas_lessThanOrEqualTo(__VA_ARGS__)
237 |
238 | #define offset(...) mas_offset(__VA_ARGS__)
239 |
240 | #endif
241 |
242 |
243 | @interface MASConstraint (AutoboxingSupport)
244 |
245 | /**
246 | * Aliases to corresponding relation methods (for shorthand macros)
247 | * Also needed to aid autocompletion
248 | */
249 | - (MASConstraint * (^)(id attr))mas_equalTo;
250 | - (MASConstraint * (^)(id attr))mas_greaterThanOrEqualTo;
251 | - (MASConstraint * (^)(id attr))mas_lessThanOrEqualTo;
252 |
253 | /**
254 | * A dummy method to aid autocompletion
255 | */
256 | - (MASConstraint * (^)(id offset))mas_offset;
257 |
258 | @end
259 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Nick Tymchenko on 1/20/14.
6 | //
7 |
8 | #import "MASConstraint.h"
9 | #import "MASConstraint+Private.h"
10 |
11 | #define MASMethodNotImplemented() \
12 | @throw [NSException exceptionWithName:NSInternalInconsistencyException \
13 | reason:[NSString stringWithFormat:@"You must override %@ in a subclass.", NSStringFromSelector(_cmd)] \
14 | userInfo:nil]
15 |
16 | @implementation MASConstraint
17 |
18 | #pragma mark - Init
19 |
20 | - (id)init {
21 | NSAssert(![self isMemberOfClass:[MASConstraint class]], @"MASConstraint is an abstract class, you should not instantiate it directly.");
22 | return [super init];
23 | }
24 |
25 | #pragma mark - NSLayoutRelation proxies
26 |
27 | - (MASConstraint * (^)(id))equalTo {
28 | return ^id(id attribute) {
29 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
30 | };
31 | }
32 |
33 | - (MASConstraint * (^)(id))mas_equalTo {
34 | return ^id(id attribute) {
35 | return self.equalToWithRelation(attribute, NSLayoutRelationEqual);
36 | };
37 | }
38 |
39 | - (MASConstraint * (^)(id))greaterThanOrEqualTo {
40 | return ^id(id attribute) {
41 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
42 | };
43 | }
44 |
45 | - (MASConstraint * (^)(id))mas_greaterThanOrEqualTo {
46 | return ^id(id attribute) {
47 | return self.equalToWithRelation(attribute, NSLayoutRelationGreaterThanOrEqual);
48 | };
49 | }
50 |
51 | - (MASConstraint * (^)(id))lessThanOrEqualTo {
52 | return ^id(id attribute) {
53 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
54 | };
55 | }
56 |
57 | - (MASConstraint * (^)(id))mas_lessThanOrEqualTo {
58 | return ^id(id attribute) {
59 | return self.equalToWithRelation(attribute, NSLayoutRelationLessThanOrEqual);
60 | };
61 | }
62 |
63 | #pragma mark - MASLayoutPriority proxies
64 |
65 | - (MASConstraint * (^)())priorityLow {
66 | return ^id{
67 | self.priority(MASLayoutPriorityDefaultLow);
68 | return self;
69 | };
70 | }
71 |
72 | - (MASConstraint * (^)())priorityMedium {
73 | return ^id{
74 | self.priority(MASLayoutPriorityDefaultMedium);
75 | return self;
76 | };
77 | }
78 |
79 | - (MASConstraint * (^)())priorityHigh {
80 | return ^id{
81 | self.priority(MASLayoutPriorityDefaultHigh);
82 | return self;
83 | };
84 | }
85 |
86 | #pragma mark - NSLayoutConstraint constant proxies
87 |
88 | - (MASConstraint * (^)(MASEdgeInsets))insets {
89 | return ^id(MASEdgeInsets insets){
90 | self.insets = insets;
91 | return self;
92 | };
93 | }
94 |
95 | - (MASConstraint * (^)(CGSize))sizeOffset {
96 | return ^id(CGSize offset) {
97 | self.sizeOffset = offset;
98 | return self;
99 | };
100 | }
101 |
102 | - (MASConstraint * (^)(CGPoint))centerOffset {
103 | return ^id(CGPoint offset) {
104 | self.centerOffset = offset;
105 | return self;
106 | };
107 | }
108 |
109 | - (MASConstraint * (^)(CGFloat))offset {
110 | return ^id(CGFloat offset){
111 | self.offset = offset;
112 | return self;
113 | };
114 | }
115 |
116 | - (MASConstraint * (^)(NSValue *value))valueOffset {
117 | return ^id(NSValue *offset) {
118 | NSAssert([offset isKindOfClass:NSValue.class], @"expected an NSValue offset, got: %@", offset);
119 | [self setLayoutConstantWithValue:offset];
120 | return self;
121 | };
122 | }
123 |
124 | - (MASConstraint * (^)(id offset))mas_offset {
125 | // Will never be called due to macro
126 | return nil;
127 | }
128 |
129 | #pragma mark - NSLayoutConstraint constant setter
130 |
131 | - (void)setLayoutConstantWithValue:(NSValue *)value {
132 | if ([value isKindOfClass:NSNumber.class]) {
133 | self.offset = [(NSNumber *)value doubleValue];
134 | } else if (strcmp(value.objCType, @encode(CGPoint)) == 0) {
135 | CGPoint point;
136 | [value getValue:&point];
137 | self.centerOffset = point;
138 | } else if (strcmp(value.objCType, @encode(CGSize)) == 0) {
139 | CGSize size;
140 | [value getValue:&size];
141 | self.sizeOffset = size;
142 | } else if (strcmp(value.objCType, @encode(MASEdgeInsets)) == 0) {
143 | MASEdgeInsets insets;
144 | [value getValue:&insets];
145 | self.insets = insets;
146 | } else {
147 | NSAssert(NO, @"attempting to set layout constant with unsupported value: %@", value);
148 | }
149 | }
150 |
151 | #pragma mark - Semantic properties
152 |
153 | - (MASConstraint *)with {
154 | return self;
155 | }
156 |
157 | - (MASConstraint *)and {
158 | return self;
159 | }
160 |
161 | #pragma mark - Chaining
162 |
163 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute __unused)layoutAttribute {
164 | MASMethodNotImplemented();
165 | }
166 |
167 | - (MASConstraint *)left {
168 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
169 | }
170 |
171 | - (MASConstraint *)top {
172 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
173 | }
174 |
175 | - (MASConstraint *)right {
176 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
177 | }
178 |
179 | - (MASConstraint *)bottom {
180 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
181 | }
182 |
183 | - (MASConstraint *)leading {
184 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
185 | }
186 |
187 | - (MASConstraint *)trailing {
188 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
189 | }
190 |
191 | - (MASConstraint *)width {
192 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
193 | }
194 |
195 | - (MASConstraint *)height {
196 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
197 | }
198 |
199 | - (MASConstraint *)centerX {
200 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
201 | }
202 |
203 | - (MASConstraint *)centerY {
204 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
205 | }
206 |
207 | - (MASConstraint *)baseline {
208 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
209 | }
210 |
211 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
212 |
213 | - (MASConstraint *)firstBaseline {
214 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline];
215 | }
216 | - (MASConstraint *)lastBaseline {
217 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline];
218 | }
219 |
220 | #endif
221 |
222 | #if TARGET_OS_IPHONE || TARGET_OS_TV
223 |
224 | - (MASConstraint *)leftMargin {
225 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
226 | }
227 |
228 | - (MASConstraint *)rightMargin {
229 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
230 | }
231 |
232 | - (MASConstraint *)topMargin {
233 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
234 | }
235 |
236 | - (MASConstraint *)bottomMargin {
237 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
238 | }
239 |
240 | - (MASConstraint *)leadingMargin {
241 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
242 | }
243 |
244 | - (MASConstraint *)trailingMargin {
245 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
246 | }
247 |
248 | - (MASConstraint *)centerXWithinMargins {
249 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
250 | }
251 |
252 | - (MASConstraint *)centerYWithinMargins {
253 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
254 | }
255 |
256 | #endif
257 |
258 | #pragma mark - Abstract
259 |
260 | - (MASConstraint * (^)(CGFloat multiplier))multipliedBy { MASMethodNotImplemented(); }
261 |
262 | - (MASConstraint * (^)(CGFloat divider))dividedBy { MASMethodNotImplemented(); }
263 |
264 | - (MASConstraint * (^)(MASLayoutPriority priority))priority { MASMethodNotImplemented(); }
265 |
266 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation { MASMethodNotImplemented(); }
267 |
268 | - (MASConstraint * (^)(id key))key { MASMethodNotImplemented(); }
269 |
270 | - (void)setInsets:(MASEdgeInsets __unused)insets { MASMethodNotImplemented(); }
271 |
272 | - (void)setSizeOffset:(CGSize __unused)sizeOffset { MASMethodNotImplemented(); }
273 |
274 | - (void)setCenterOffset:(CGPoint __unused)centerOffset { MASMethodNotImplemented(); }
275 |
276 | - (void)setOffset:(CGFloat __unused)offset { MASMethodNotImplemented(); }
277 |
278 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
279 |
280 | - (MASConstraint *)animator { MASMethodNotImplemented(); }
281 |
282 | #endif
283 |
284 | - (void)activate { MASMethodNotImplemented(); }
285 |
286 | - (void)deactivate { MASMethodNotImplemented(); }
287 |
288 | - (void)install { MASMethodNotImplemented(); }
289 |
290 | - (void)uninstall { MASMethodNotImplemented(); }
291 |
292 | @end
293 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASConstraintMaker.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraint.h"
10 | #import "MASUtilities.h"
11 |
12 | typedef NS_OPTIONS(NSInteger, MASAttribute) {
13 | MASAttributeLeft = 1 << NSLayoutAttributeLeft,
14 | MASAttributeRight = 1 << NSLayoutAttributeRight,
15 | MASAttributeTop = 1 << NSLayoutAttributeTop,
16 | MASAttributeBottom = 1 << NSLayoutAttributeBottom,
17 | MASAttributeLeading = 1 << NSLayoutAttributeLeading,
18 | MASAttributeTrailing = 1 << NSLayoutAttributeTrailing,
19 | MASAttributeWidth = 1 << NSLayoutAttributeWidth,
20 | MASAttributeHeight = 1 << NSLayoutAttributeHeight,
21 | MASAttributeCenterX = 1 << NSLayoutAttributeCenterX,
22 | MASAttributeCenterY = 1 << NSLayoutAttributeCenterY,
23 | MASAttributeBaseline = 1 << NSLayoutAttributeBaseline,
24 |
25 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
26 |
27 | MASAttributeFirstBaseline = 1 << NSLayoutAttributeFirstBaseline,
28 | MASAttributeLastBaseline = 1 << NSLayoutAttributeLastBaseline,
29 |
30 | #endif
31 |
32 | #if TARGET_OS_IPHONE || TARGET_OS_TV
33 |
34 | MASAttributeLeftMargin = 1 << NSLayoutAttributeLeftMargin,
35 | MASAttributeRightMargin = 1 << NSLayoutAttributeRightMargin,
36 | MASAttributeTopMargin = 1 << NSLayoutAttributeTopMargin,
37 | MASAttributeBottomMargin = 1 << NSLayoutAttributeBottomMargin,
38 | MASAttributeLeadingMargin = 1 << NSLayoutAttributeLeadingMargin,
39 | MASAttributeTrailingMargin = 1 << NSLayoutAttributeTrailingMargin,
40 | MASAttributeCenterXWithinMargins = 1 << NSLayoutAttributeCenterXWithinMargins,
41 | MASAttributeCenterYWithinMargins = 1 << NSLayoutAttributeCenterYWithinMargins,
42 |
43 | #endif
44 |
45 | };
46 |
47 | /**
48 | * Provides factory methods for creating MASConstraints.
49 | * Constraints are collected until they are ready to be installed
50 | *
51 | */
52 | @interface MASConstraintMaker : NSObject
53 |
54 | /**
55 | * The following properties return a new MASViewConstraint
56 | * with the first item set to the makers associated view and the appropriate MASViewAttribute
57 | */
58 | @property (nonatomic, strong, readonly) MASConstraint *left;
59 | @property (nonatomic, strong, readonly) MASConstraint *top;
60 | @property (nonatomic, strong, readonly) MASConstraint *right;
61 | @property (nonatomic, strong, readonly) MASConstraint *bottom;
62 | @property (nonatomic, strong, readonly) MASConstraint *leading;
63 | @property (nonatomic, strong, readonly) MASConstraint *trailing;
64 | @property (nonatomic, strong, readonly) MASConstraint *width;
65 | @property (nonatomic, strong, readonly) MASConstraint *height;
66 | @property (nonatomic, strong, readonly) MASConstraint *centerX;
67 | @property (nonatomic, strong, readonly) MASConstraint *centerY;
68 | @property (nonatomic, strong, readonly) MASConstraint *baseline;
69 |
70 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
71 |
72 | @property (nonatomic, strong, readonly) MASConstraint *firstBaseline;
73 | @property (nonatomic, strong, readonly) MASConstraint *lastBaseline;
74 |
75 | #endif
76 |
77 | #if TARGET_OS_IPHONE || TARGET_OS_TV
78 |
79 | @property (nonatomic, strong, readonly) MASConstraint *leftMargin;
80 | @property (nonatomic, strong, readonly) MASConstraint *rightMargin;
81 | @property (nonatomic, strong, readonly) MASConstraint *topMargin;
82 | @property (nonatomic, strong, readonly) MASConstraint *bottomMargin;
83 | @property (nonatomic, strong, readonly) MASConstraint *leadingMargin;
84 | @property (nonatomic, strong, readonly) MASConstraint *trailingMargin;
85 | @property (nonatomic, strong, readonly) MASConstraint *centerXWithinMargins;
86 | @property (nonatomic, strong, readonly) MASConstraint *centerYWithinMargins;
87 |
88 | #endif
89 |
90 | /**
91 | * Returns a block which creates a new MASCompositeConstraint with the first item set
92 | * to the makers associated view and children corresponding to the set bits in the
93 | * MASAttribute parameter. Combine multiple attributes via binary-or.
94 | */
95 | @property (nonatomic, strong, readonly) MASConstraint *(^attributes)(MASAttribute attrs);
96 |
97 | /**
98 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeEdges
99 | * which generates the appropriate MASViewConstraint children (top, left, bottom, right)
100 | * with the first item set to the makers associated view
101 | */
102 | @property (nonatomic, strong, readonly) MASConstraint *edges;
103 |
104 | /**
105 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeSize
106 | * which generates the appropriate MASViewConstraint children (width, height)
107 | * with the first item set to the makers associated view
108 | */
109 | @property (nonatomic, strong, readonly) MASConstraint *size;
110 |
111 | /**
112 | * Creates a MASCompositeConstraint with type MASCompositeConstraintTypeCenter
113 | * which generates the appropriate MASViewConstraint children (centerX, centerY)
114 | * with the first item set to the makers associated view
115 | */
116 | @property (nonatomic, strong, readonly) MASConstraint *center;
117 |
118 | /**
119 | * Whether or not to check for an existing constraint instead of adding constraint
120 | */
121 | @property (nonatomic, assign) BOOL updateExisting;
122 |
123 | /**
124 | * Whether or not to remove existing constraints prior to installing
125 | */
126 | @property (nonatomic, assign) BOOL removeExisting;
127 |
128 | /**
129 | * initialises the maker with a default view
130 | *
131 | * @param view any MASConstrait are created with this view as the first item
132 | *
133 | * @return a new MASConstraintMaker
134 | */
135 | - (id)initWithView:(MAS_VIEW *)view;
136 |
137 | /**
138 | * Calls install method on any MASConstraints which have been created by this maker
139 | *
140 | * @return an array of all the installed MASConstraints
141 | */
142 | - (NSArray *)install;
143 |
144 | - (MASConstraint * (^)(dispatch_block_t))group;
145 |
146 | @end
147 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASConstraintMaker.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraintBuilder.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASConstraintMaker.h"
10 | #import "MASViewConstraint.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASConstraint+Private.h"
13 | #import "MASViewAttribute.h"
14 | #import "View+MASAdditions.h"
15 |
16 | @interface MASConstraintMaker ()
17 |
18 | @property (nonatomic, weak) MAS_VIEW *view;
19 | @property (nonatomic, strong) NSMutableArray *constraints;
20 |
21 | @end
22 |
23 | @implementation MASConstraintMaker
24 |
25 | - (id)initWithView:(MAS_VIEW *)view {
26 | self = [super init];
27 | if (!self) return nil;
28 |
29 | self.view = view;
30 | self.constraints = NSMutableArray.new;
31 |
32 | return self;
33 | }
34 |
35 | - (NSArray *)install {
36 | if (self.removeExisting) {
37 | NSArray *installedConstraints = [MASViewConstraint installedConstraintsForView:self.view];
38 | for (MASConstraint *constraint in installedConstraints) {
39 | [constraint uninstall];
40 | }
41 | }
42 | NSArray *constraints = self.constraints.copy;
43 | for (MASConstraint *constraint in constraints) {
44 | constraint.updateExisting = self.updateExisting;
45 | [constraint install];
46 | }
47 | [self.constraints removeAllObjects];
48 | return constraints;
49 | }
50 |
51 | #pragma mark - MASConstraintDelegate
52 |
53 | - (void)constraint:(MASConstraint *)constraint shouldBeReplacedWithConstraint:(MASConstraint *)replacementConstraint {
54 | NSUInteger index = [self.constraints indexOfObject:constraint];
55 | NSAssert(index != NSNotFound, @"Could not find constraint %@", constraint);
56 | [self.constraints replaceObjectAtIndex:index withObject:replacementConstraint];
57 | }
58 |
59 | - (MASConstraint *)constraint:(MASConstraint *)constraint addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
60 | MASViewAttribute *viewAttribute = [[MASViewAttribute alloc] initWithView:self.view layoutAttribute:layoutAttribute];
61 | MASViewConstraint *newConstraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:viewAttribute];
62 | if ([constraint isKindOfClass:MASViewConstraint.class]) {
63 | //replace with composite constraint
64 | NSArray *children = @[constraint, newConstraint];
65 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
66 | compositeConstraint.delegate = self;
67 | [self constraint:constraint shouldBeReplacedWithConstraint:compositeConstraint];
68 | return compositeConstraint;
69 | }
70 | if (!constraint) {
71 | newConstraint.delegate = self;
72 | [self.constraints addObject:newConstraint];
73 | }
74 | return newConstraint;
75 | }
76 |
77 | - (MASConstraint *)addConstraintWithAttributes:(MASAttribute)attrs {
78 | __unused MASAttribute anyAttribute = (MASAttributeLeft | MASAttributeRight | MASAttributeTop | MASAttributeBottom | MASAttributeLeading
79 | | MASAttributeTrailing | MASAttributeWidth | MASAttributeHeight | MASAttributeCenterX
80 | | MASAttributeCenterY | MASAttributeBaseline
81 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
82 | | MASAttributeFirstBaseline | MASAttributeLastBaseline
83 | #endif
84 | #if TARGET_OS_IPHONE || TARGET_OS_TV
85 | | MASAttributeLeftMargin | MASAttributeRightMargin | MASAttributeTopMargin | MASAttributeBottomMargin
86 | | MASAttributeLeadingMargin | MASAttributeTrailingMargin | MASAttributeCenterXWithinMargins
87 | | MASAttributeCenterYWithinMargins
88 | #endif
89 | );
90 |
91 | NSAssert((attrs & anyAttribute) != 0, @"You didn't pass any attribute to make.attributes(...)");
92 |
93 | NSMutableArray *attributes = [NSMutableArray array];
94 |
95 | if (attrs & MASAttributeLeft) [attributes addObject:self.view.mas_left];
96 | if (attrs & MASAttributeRight) [attributes addObject:self.view.mas_right];
97 | if (attrs & MASAttributeTop) [attributes addObject:self.view.mas_top];
98 | if (attrs & MASAttributeBottom) [attributes addObject:self.view.mas_bottom];
99 | if (attrs & MASAttributeLeading) [attributes addObject:self.view.mas_leading];
100 | if (attrs & MASAttributeTrailing) [attributes addObject:self.view.mas_trailing];
101 | if (attrs & MASAttributeWidth) [attributes addObject:self.view.mas_width];
102 | if (attrs & MASAttributeHeight) [attributes addObject:self.view.mas_height];
103 | if (attrs & MASAttributeCenterX) [attributes addObject:self.view.mas_centerX];
104 | if (attrs & MASAttributeCenterY) [attributes addObject:self.view.mas_centerY];
105 | if (attrs & MASAttributeBaseline) [attributes addObject:self.view.mas_baseline];
106 |
107 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
108 |
109 | if (attrs & MASAttributeFirstBaseline) [attributes addObject:self.view.mas_firstBaseline];
110 | if (attrs & MASAttributeLastBaseline) [attributes addObject:self.view.mas_lastBaseline];
111 |
112 | #endif
113 |
114 | #if TARGET_OS_IPHONE || TARGET_OS_TV
115 |
116 | if (attrs & MASAttributeLeftMargin) [attributes addObject:self.view.mas_leftMargin];
117 | if (attrs & MASAttributeRightMargin) [attributes addObject:self.view.mas_rightMargin];
118 | if (attrs & MASAttributeTopMargin) [attributes addObject:self.view.mas_topMargin];
119 | if (attrs & MASAttributeBottomMargin) [attributes addObject:self.view.mas_bottomMargin];
120 | if (attrs & MASAttributeLeadingMargin) [attributes addObject:self.view.mas_leadingMargin];
121 | if (attrs & MASAttributeTrailingMargin) [attributes addObject:self.view.mas_trailingMargin];
122 | if (attrs & MASAttributeCenterXWithinMargins) [attributes addObject:self.view.mas_centerXWithinMargins];
123 | if (attrs & MASAttributeCenterYWithinMargins) [attributes addObject:self.view.mas_centerYWithinMargins];
124 |
125 | #endif
126 |
127 | NSMutableArray *children = [NSMutableArray arrayWithCapacity:attributes.count];
128 |
129 | for (MASViewAttribute *a in attributes) {
130 | [children addObject:[[MASViewConstraint alloc] initWithFirstViewAttribute:a]];
131 | }
132 |
133 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
134 | constraint.delegate = self;
135 | [self.constraints addObject:constraint];
136 | return constraint;
137 | }
138 |
139 | #pragma mark - standard Attributes
140 |
141 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
142 | return [self constraint:nil addConstraintWithLayoutAttribute:layoutAttribute];
143 | }
144 |
145 | - (MASConstraint *)left {
146 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeft];
147 | }
148 |
149 | - (MASConstraint *)top {
150 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTop];
151 | }
152 |
153 | - (MASConstraint *)right {
154 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRight];
155 | }
156 |
157 | - (MASConstraint *)bottom {
158 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottom];
159 | }
160 |
161 | - (MASConstraint *)leading {
162 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeading];
163 | }
164 |
165 | - (MASConstraint *)trailing {
166 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailing];
167 | }
168 |
169 | - (MASConstraint *)width {
170 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeWidth];
171 | }
172 |
173 | - (MASConstraint *)height {
174 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeHeight];
175 | }
176 |
177 | - (MASConstraint *)centerX {
178 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterX];
179 | }
180 |
181 | - (MASConstraint *)centerY {
182 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterY];
183 | }
184 |
185 | - (MASConstraint *)baseline {
186 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBaseline];
187 | }
188 |
189 | - (MASConstraint *(^)(MASAttribute))attributes {
190 | return ^(MASAttribute attrs){
191 | return [self addConstraintWithAttributes:attrs];
192 | };
193 | }
194 |
195 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
196 |
197 | - (MASConstraint *)firstBaseline {
198 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeFirstBaseline];
199 | }
200 |
201 | - (MASConstraint *)lastBaseline {
202 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLastBaseline];
203 | }
204 |
205 | #endif
206 |
207 |
208 | #if TARGET_OS_IPHONE || TARGET_OS_TV
209 |
210 | - (MASConstraint *)leftMargin {
211 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeftMargin];
212 | }
213 |
214 | - (MASConstraint *)rightMargin {
215 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeRightMargin];
216 | }
217 |
218 | - (MASConstraint *)topMargin {
219 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTopMargin];
220 | }
221 |
222 | - (MASConstraint *)bottomMargin {
223 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeBottomMargin];
224 | }
225 |
226 | - (MASConstraint *)leadingMargin {
227 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeLeadingMargin];
228 | }
229 |
230 | - (MASConstraint *)trailingMargin {
231 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeTrailingMargin];
232 | }
233 |
234 | - (MASConstraint *)centerXWithinMargins {
235 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterXWithinMargins];
236 | }
237 |
238 | - (MASConstraint *)centerYWithinMargins {
239 | return [self addConstraintWithLayoutAttribute:NSLayoutAttributeCenterYWithinMargins];
240 | }
241 |
242 | #endif
243 |
244 |
245 | #pragma mark - composite Attributes
246 |
247 | - (MASConstraint *)edges {
248 | return [self addConstraintWithAttributes:MASAttributeTop | MASAttributeLeft | MASAttributeRight | MASAttributeBottom];
249 | }
250 |
251 | - (MASConstraint *)size {
252 | return [self addConstraintWithAttributes:MASAttributeWidth | MASAttributeHeight];
253 | }
254 |
255 | - (MASConstraint *)center {
256 | return [self addConstraintWithAttributes:MASAttributeCenterX | MASAttributeCenterY];
257 | }
258 |
259 | #pragma mark - grouping
260 |
261 | - (MASConstraint *(^)(dispatch_block_t group))group {
262 | return ^id(dispatch_block_t group) {
263 | NSInteger previousCount = self.constraints.count;
264 | group();
265 |
266 | NSArray *children = [self.constraints subarrayWithRange:NSMakeRange(previousCount, self.constraints.count - previousCount)];
267 | MASCompositeConstraint *constraint = [[MASCompositeConstraint alloc] initWithChildren:children];
268 | constraint.delegate = self;
269 | return constraint;
270 | };
271 | }
272 |
273 | @end
274 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASLayoutConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * When you are debugging or printing the constraints attached to a view this subclass
13 | * makes it easier to identify which constraints have been created via Masonry
14 | */
15 | @interface MASLayoutConstraint : NSLayoutConstraint
16 |
17 | /**
18 | * a key to associate with this constraint
19 | */
20 | @property (nonatomic, strong) id mas_key;
21 |
22 | @end
23 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASLayoutConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASLayoutConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASLayoutConstraint.h"
10 |
11 | @implementation MASLayoutConstraint
12 |
13 | @end
14 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASUtilities.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASUtilities.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 19/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 |
12 |
13 | #if TARGET_OS_IPHONE || TARGET_OS_TV
14 |
15 | #import
16 | #define MAS_VIEW UIView
17 | #define MAS_VIEW_CONTROLLER UIViewController
18 | #define MASEdgeInsets UIEdgeInsets
19 |
20 | typedef UILayoutPriority MASLayoutPriority;
21 | static const MASLayoutPriority MASLayoutPriorityRequired = UILayoutPriorityRequired;
22 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = UILayoutPriorityDefaultHigh;
23 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 500;
24 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = UILayoutPriorityDefaultLow;
25 | static const MASLayoutPriority MASLayoutPriorityFittingSizeLevel = UILayoutPriorityFittingSizeLevel;
26 |
27 | #elif TARGET_OS_MAC
28 |
29 | #import
30 | #define MAS_VIEW NSView
31 | #define MASEdgeInsets NSEdgeInsets
32 |
33 | typedef NSLayoutPriority MASLayoutPriority;
34 | static const MASLayoutPriority MASLayoutPriorityRequired = NSLayoutPriorityRequired;
35 | static const MASLayoutPriority MASLayoutPriorityDefaultHigh = NSLayoutPriorityDefaultHigh;
36 | static const MASLayoutPriority MASLayoutPriorityDragThatCanResizeWindow = NSLayoutPriorityDragThatCanResizeWindow;
37 | static const MASLayoutPriority MASLayoutPriorityDefaultMedium = 501;
38 | static const MASLayoutPriority MASLayoutPriorityWindowSizeStayPut = NSLayoutPriorityWindowSizeStayPut;
39 | static const MASLayoutPriority MASLayoutPriorityDragThatCannotResizeWindow = NSLayoutPriorityDragThatCannotResizeWindow;
40 | static const MASLayoutPriority MASLayoutPriorityDefaultLow = NSLayoutPriorityDefaultLow;
41 | static const MASLayoutPriority MASLayoutPriorityFittingSizeCompression = NSLayoutPriorityFittingSizeCompression;
42 |
43 | #endif
44 |
45 | /**
46 | * Allows you to attach keys to objects matching the variable names passed.
47 | *
48 | * view1.mas_key = @"view1", view2.mas_key = @"view2";
49 | *
50 | * is equivalent to:
51 | *
52 | * MASAttachKeys(view1, view2);
53 | */
54 | #define MASAttachKeys(...) \
55 | { \
56 | NSDictionary *keyPairs = NSDictionaryOfVariableBindings(__VA_ARGS__); \
57 | for (id key in keyPairs.allKeys) { \
58 | id obj = keyPairs[key]; \
59 | NSAssert([obj respondsToSelector:@selector(setMas_key:)], \
60 | @"Cannot attach mas_key to %@", obj); \
61 | [obj setMas_key:key]; \
62 | } \
63 | }
64 |
65 | /**
66 | * Used to create object hashes
67 | * Based on http://www.mikeash.com/pyblog/friday-qa-2010-06-18-implementing-equality-and-hashing.html
68 | */
69 | #define MAS_NSUINT_BIT (CHAR_BIT * sizeof(NSUInteger))
70 | #define MAS_NSUINTROTATE(val, howmuch) ((((NSUInteger)val) << howmuch) | (((NSUInteger)val) >> (MAS_NSUINT_BIT - howmuch)))
71 |
72 | /**
73 | * Given a scalar or struct value, wraps it in NSValue
74 | * Based on EXPObjectify: https://github.com/specta/expecta
75 | */
76 | static inline id _MASBoxValue(const char *type, ...) {
77 | va_list v;
78 | va_start(v, type);
79 | id obj = nil;
80 | if (strcmp(type, @encode(id)) == 0) {
81 | id actual = va_arg(v, id);
82 | obj = actual;
83 | } else if (strcmp(type, @encode(CGPoint)) == 0) {
84 | CGPoint actual = (CGPoint)va_arg(v, CGPoint);
85 | obj = [NSValue value:&actual withObjCType:type];
86 | } else if (strcmp(type, @encode(CGSize)) == 0) {
87 | CGSize actual = (CGSize)va_arg(v, CGSize);
88 | obj = [NSValue value:&actual withObjCType:type];
89 | } else if (strcmp(type, @encode(MASEdgeInsets)) == 0) {
90 | MASEdgeInsets actual = (MASEdgeInsets)va_arg(v, MASEdgeInsets);
91 | obj = [NSValue value:&actual withObjCType:type];
92 | } else if (strcmp(type, @encode(double)) == 0) {
93 | double actual = (double)va_arg(v, double);
94 | obj = [NSNumber numberWithDouble:actual];
95 | } else if (strcmp(type, @encode(float)) == 0) {
96 | float actual = (float)va_arg(v, double);
97 | obj = [NSNumber numberWithFloat:actual];
98 | } else if (strcmp(type, @encode(int)) == 0) {
99 | int actual = (int)va_arg(v, int);
100 | obj = [NSNumber numberWithInt:actual];
101 | } else if (strcmp(type, @encode(long)) == 0) {
102 | long actual = (long)va_arg(v, long);
103 | obj = [NSNumber numberWithLong:actual];
104 | } else if (strcmp(type, @encode(long long)) == 0) {
105 | long long actual = (long long)va_arg(v, long long);
106 | obj = [NSNumber numberWithLongLong:actual];
107 | } else if (strcmp(type, @encode(short)) == 0) {
108 | short actual = (short)va_arg(v, int);
109 | obj = [NSNumber numberWithShort:actual];
110 | } else if (strcmp(type, @encode(char)) == 0) {
111 | char actual = (char)va_arg(v, int);
112 | obj = [NSNumber numberWithChar:actual];
113 | } else if (strcmp(type, @encode(bool)) == 0) {
114 | bool actual = (bool)va_arg(v, int);
115 | obj = [NSNumber numberWithBool:actual];
116 | } else if (strcmp(type, @encode(unsigned char)) == 0) {
117 | unsigned char actual = (unsigned char)va_arg(v, unsigned int);
118 | obj = [NSNumber numberWithUnsignedChar:actual];
119 | } else if (strcmp(type, @encode(unsigned int)) == 0) {
120 | unsigned int actual = (unsigned int)va_arg(v, unsigned int);
121 | obj = [NSNumber numberWithUnsignedInt:actual];
122 | } else if (strcmp(type, @encode(unsigned long)) == 0) {
123 | unsigned long actual = (unsigned long)va_arg(v, unsigned long);
124 | obj = [NSNumber numberWithUnsignedLong:actual];
125 | } else if (strcmp(type, @encode(unsigned long long)) == 0) {
126 | unsigned long long actual = (unsigned long long)va_arg(v, unsigned long long);
127 | obj = [NSNumber numberWithUnsignedLongLong:actual];
128 | } else if (strcmp(type, @encode(unsigned short)) == 0) {
129 | unsigned short actual = (unsigned short)va_arg(v, unsigned int);
130 | obj = [NSNumber numberWithUnsignedShort:actual];
131 | }
132 | va_end(v);
133 | return obj;
134 | }
135 |
136 | #define MASBoxValue(value) _MASBoxValue(@encode(__typeof__((value))), (value))
137 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASViewAttribute.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * An immutable tuple which stores the view and the related NSLayoutAttribute.
13 | * Describes part of either the left or right hand side of a constraint equation
14 | */
15 | @interface MASViewAttribute : NSObject
16 |
17 | /**
18 | * The view which the reciever relates to. Can be nil if item is not a view.
19 | */
20 | @property (nonatomic, weak, readonly) MAS_VIEW *view;
21 |
22 | /**
23 | * The item which the reciever relates to.
24 | */
25 | @property (nonatomic, weak, readonly) id item;
26 |
27 | /**
28 | * The attribute which the reciever relates to
29 | */
30 | @property (nonatomic, assign, readonly) NSLayoutAttribute layoutAttribute;
31 |
32 | /**
33 | * Convenience initializer.
34 | */
35 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute;
36 |
37 | /**
38 | * The designated initializer.
39 | */
40 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute;
41 |
42 | /**
43 | * Determine whether the layoutAttribute is a size attribute
44 | *
45 | * @return YES if layoutAttribute is equal to NSLayoutAttributeWidth or NSLayoutAttributeHeight
46 | */
47 | - (BOOL)isSizeAttribute;
48 |
49 | @end
50 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASViewAttribute.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASAttribute.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 21/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 |
11 | @implementation MASViewAttribute
12 |
13 | - (id)initWithView:(MAS_VIEW *)view layoutAttribute:(NSLayoutAttribute)layoutAttribute {
14 | self = [self initWithView:view item:view layoutAttribute:layoutAttribute];
15 | return self;
16 | }
17 |
18 | - (id)initWithView:(MAS_VIEW *)view item:(id)item layoutAttribute:(NSLayoutAttribute)layoutAttribute {
19 | self = [super init];
20 | if (!self) return nil;
21 |
22 | _view = view;
23 | _item = item;
24 | _layoutAttribute = layoutAttribute;
25 |
26 | return self;
27 | }
28 |
29 | - (BOOL)isSizeAttribute {
30 | return self.layoutAttribute == NSLayoutAttributeWidth
31 | || self.layoutAttribute == NSLayoutAttributeHeight;
32 | }
33 |
34 | - (BOOL)isEqual:(MASViewAttribute *)viewAttribute {
35 | if ([viewAttribute isKindOfClass:self.class]) {
36 | return self.view == viewAttribute.view
37 | && self.layoutAttribute == viewAttribute.layoutAttribute;
38 | }
39 | return [super isEqual:viewAttribute];
40 | }
41 |
42 | - (NSUInteger)hash {
43 | return MAS_NSUINTROTATE([self.view hash], MAS_NSUINT_BIT / 2) ^ self.layoutAttribute;
44 | }
45 |
46 | @end
47 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASViewConstraint.h:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewAttribute.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 | #import "MASUtilities.h"
13 |
14 | /**
15 | * A single constraint.
16 | * Contains the attributes neccessary for creating a NSLayoutConstraint and adding it to the appropriate view
17 | */
18 | @interface MASViewConstraint : MASConstraint
19 |
20 | /**
21 | * First item/view and first attribute of the NSLayoutConstraint
22 | */
23 | @property (nonatomic, strong, readonly) MASViewAttribute *firstViewAttribute;
24 |
25 | /**
26 | * Second item/view and second attribute of the NSLayoutConstraint
27 | */
28 | @property (nonatomic, strong, readonly) MASViewAttribute *secondViewAttribute;
29 |
30 | /**
31 | * initialises the MASViewConstraint with the first part of the equation
32 | *
33 | * @param firstViewAttribute view.mas_left, view.mas_width etc.
34 | *
35 | * @return a new view constraint
36 | */
37 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute;
38 |
39 | /**
40 | * Returns all MASViewConstraints installed with this view as a first item.
41 | *
42 | * @param view A view to retrieve constraints for.
43 | *
44 | * @return An array of MASViewConstraints.
45 | */
46 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view;
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/MASViewConstraint.m:
--------------------------------------------------------------------------------
1 | //
2 | // MASConstraint.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASViewConstraint.h"
10 | #import "MASConstraint+Private.h"
11 | #import "MASCompositeConstraint.h"
12 | #import "MASLayoutConstraint.h"
13 | #import "View+MASAdditions.h"
14 | #import
15 |
16 | @interface MAS_VIEW (MASConstraints)
17 |
18 | @property (nonatomic, readonly) NSMutableSet *mas_installedConstraints;
19 |
20 | @end
21 |
22 | @implementation MAS_VIEW (MASConstraints)
23 |
24 | static char kInstalledConstraintsKey;
25 |
26 | - (NSMutableSet *)mas_installedConstraints {
27 | NSMutableSet *constraints = objc_getAssociatedObject(self, &kInstalledConstraintsKey);
28 | if (!constraints) {
29 | constraints = [NSMutableSet set];
30 | objc_setAssociatedObject(self, &kInstalledConstraintsKey, constraints, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
31 | }
32 | return constraints;
33 | }
34 |
35 | @end
36 |
37 |
38 | @interface MASViewConstraint ()
39 |
40 | @property (nonatomic, strong, readwrite) MASViewAttribute *secondViewAttribute;
41 | @property (nonatomic, weak) MAS_VIEW *installedView;
42 | @property (nonatomic, weak) MASLayoutConstraint *layoutConstraint;
43 | @property (nonatomic, assign) NSLayoutRelation layoutRelation;
44 | @property (nonatomic, assign) MASLayoutPriority layoutPriority;
45 | @property (nonatomic, assign) CGFloat layoutMultiplier;
46 | @property (nonatomic, assign) CGFloat layoutConstant;
47 | @property (nonatomic, assign) BOOL hasLayoutRelation;
48 | @property (nonatomic, strong) id mas_key;
49 | @property (nonatomic, assign) BOOL useAnimator;
50 |
51 | @end
52 |
53 | @implementation MASViewConstraint
54 |
55 | - (id)initWithFirstViewAttribute:(MASViewAttribute *)firstViewAttribute {
56 | self = [super init];
57 | if (!self) return nil;
58 |
59 | _firstViewAttribute = firstViewAttribute;
60 | self.layoutPriority = MASLayoutPriorityRequired;
61 | self.layoutMultiplier = 1;
62 |
63 | return self;
64 | }
65 |
66 | #pragma mark - NSCoping
67 |
68 | - (id)copyWithZone:(NSZone __unused *)zone {
69 | MASViewConstraint *constraint = [[MASViewConstraint alloc] initWithFirstViewAttribute:self.firstViewAttribute];
70 | constraint.layoutConstant = self.layoutConstant;
71 | constraint.layoutRelation = self.layoutRelation;
72 | constraint.layoutPriority = self.layoutPriority;
73 | constraint.layoutMultiplier = self.layoutMultiplier;
74 | constraint.delegate = self.delegate;
75 | return constraint;
76 | }
77 |
78 | #pragma mark - Public
79 |
80 | + (NSArray *)installedConstraintsForView:(MAS_VIEW *)view {
81 | return [view.mas_installedConstraints allObjects];
82 | }
83 |
84 | #pragma mark - Private
85 |
86 | - (void)setLayoutConstant:(CGFloat)layoutConstant {
87 | _layoutConstant = layoutConstant;
88 |
89 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
90 | if (self.useAnimator) {
91 | [self.layoutConstraint.animator setConstant:layoutConstant];
92 | } else {
93 | self.layoutConstraint.constant = layoutConstant;
94 | }
95 | #else
96 | self.layoutConstraint.constant = layoutConstant;
97 | #endif
98 | }
99 |
100 | - (void)setLayoutRelation:(NSLayoutRelation)layoutRelation {
101 | _layoutRelation = layoutRelation;
102 | self.hasLayoutRelation = YES;
103 | }
104 |
105 | - (BOOL)supportsActiveProperty {
106 | return [self.layoutConstraint respondsToSelector:@selector(isActive)];
107 | }
108 |
109 | - (BOOL)isActive {
110 | BOOL active = YES;
111 | if ([self supportsActiveProperty]) {
112 | active = [self.layoutConstraint isActive];
113 | }
114 |
115 | return active;
116 | }
117 |
118 | - (BOOL)hasBeenInstalled {
119 | return (self.layoutConstraint != nil) && [self isActive];
120 | }
121 |
122 | - (void)setSecondViewAttribute:(id)secondViewAttribute {
123 | if ([secondViewAttribute isKindOfClass:NSValue.class]) {
124 | [self setLayoutConstantWithValue:secondViewAttribute];
125 | } else if ([secondViewAttribute isKindOfClass:MAS_VIEW.class]) {
126 | _secondViewAttribute = [[MASViewAttribute alloc] initWithView:secondViewAttribute layoutAttribute:self.firstViewAttribute.layoutAttribute];
127 | } else if ([secondViewAttribute isKindOfClass:MASViewAttribute.class]) {
128 | _secondViewAttribute = secondViewAttribute;
129 | } else {
130 | NSAssert(NO, @"attempting to add unsupported attribute: %@", secondViewAttribute);
131 | }
132 | }
133 |
134 | #pragma mark - NSLayoutConstraint multiplier proxies
135 |
136 | - (MASConstraint * (^)(CGFloat))multipliedBy {
137 | return ^id(CGFloat multiplier) {
138 | NSAssert(!self.hasBeenInstalled,
139 | @"Cannot modify constraint multiplier after it has been installed");
140 |
141 | self.layoutMultiplier = multiplier;
142 | return self;
143 | };
144 | }
145 |
146 |
147 | - (MASConstraint * (^)(CGFloat))dividedBy {
148 | return ^id(CGFloat divider) {
149 | NSAssert(!self.hasBeenInstalled,
150 | @"Cannot modify constraint multiplier after it has been installed");
151 |
152 | self.layoutMultiplier = 1.0/divider;
153 | return self;
154 | };
155 | }
156 |
157 | #pragma mark - MASLayoutPriority proxy
158 |
159 | - (MASConstraint * (^)(MASLayoutPriority))priority {
160 | return ^id(MASLayoutPriority priority) {
161 | NSAssert(!self.hasBeenInstalled,
162 | @"Cannot modify constraint priority after it has been installed");
163 |
164 | self.layoutPriority = priority;
165 | return self;
166 | };
167 | }
168 |
169 | #pragma mark - NSLayoutRelation proxy
170 |
171 | - (MASConstraint * (^)(id, NSLayoutRelation))equalToWithRelation {
172 | return ^id(id attribute, NSLayoutRelation relation) {
173 | if ([attribute isKindOfClass:NSArray.class]) {
174 | NSAssert(!self.hasLayoutRelation, @"Redefinition of constraint relation");
175 | NSMutableArray *children = NSMutableArray.new;
176 | for (id attr in attribute) {
177 | MASViewConstraint *viewConstraint = [self copy];
178 | viewConstraint.secondViewAttribute = attr;
179 | [children addObject:viewConstraint];
180 | }
181 | MASCompositeConstraint *compositeConstraint = [[MASCompositeConstraint alloc] initWithChildren:children];
182 | compositeConstraint.delegate = self.delegate;
183 | [self.delegate constraint:self shouldBeReplacedWithConstraint:compositeConstraint];
184 | return compositeConstraint;
185 | } else {
186 | NSAssert(!self.hasLayoutRelation || self.layoutRelation == relation && [attribute isKindOfClass:NSValue.class], @"Redefinition of constraint relation");
187 | self.layoutRelation = relation;
188 | self.secondViewAttribute = attribute;
189 | return self;
190 | }
191 | };
192 | }
193 |
194 | #pragma mark - Semantic properties
195 |
196 | - (MASConstraint *)with {
197 | return self;
198 | }
199 |
200 | - (MASConstraint *)and {
201 | return self;
202 | }
203 |
204 | #pragma mark - attribute chaining
205 |
206 | - (MASConstraint *)addConstraintWithLayoutAttribute:(NSLayoutAttribute)layoutAttribute {
207 | NSAssert(!self.hasLayoutRelation, @"Attributes should be chained before defining the constraint relation");
208 |
209 | return [self.delegate constraint:self addConstraintWithLayoutAttribute:layoutAttribute];
210 | }
211 |
212 | #pragma mark - Animator proxy
213 |
214 | #if TARGET_OS_MAC && !(TARGET_OS_IPHONE || TARGET_OS_TV)
215 |
216 | - (MASConstraint *)animator {
217 | self.useAnimator = YES;
218 | return self;
219 | }
220 |
221 | #endif
222 |
223 | #pragma mark - debug helpers
224 |
225 | - (MASConstraint * (^)(id))key {
226 | return ^id(id key) {
227 | self.mas_key = key;
228 | return self;
229 | };
230 | }
231 |
232 | #pragma mark - NSLayoutConstraint constant setters
233 |
234 | - (void)setInsets:(MASEdgeInsets)insets {
235 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
236 | switch (layoutAttribute) {
237 | case NSLayoutAttributeLeft:
238 | case NSLayoutAttributeLeading:
239 | self.layoutConstant = insets.left;
240 | break;
241 | case NSLayoutAttributeTop:
242 | self.layoutConstant = insets.top;
243 | break;
244 | case NSLayoutAttributeBottom:
245 | self.layoutConstant = -insets.bottom;
246 | break;
247 | case NSLayoutAttributeRight:
248 | case NSLayoutAttributeTrailing:
249 | self.layoutConstant = -insets.right;
250 | break;
251 | default:
252 | break;
253 | }
254 | }
255 |
256 | - (void)setOffset:(CGFloat)offset {
257 | self.layoutConstant = offset;
258 | }
259 |
260 | - (void)setSizeOffset:(CGSize)sizeOffset {
261 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
262 | switch (layoutAttribute) {
263 | case NSLayoutAttributeWidth:
264 | self.layoutConstant = sizeOffset.width;
265 | break;
266 | case NSLayoutAttributeHeight:
267 | self.layoutConstant = sizeOffset.height;
268 | break;
269 | default:
270 | break;
271 | }
272 | }
273 |
274 | - (void)setCenterOffset:(CGPoint)centerOffset {
275 | NSLayoutAttribute layoutAttribute = self.firstViewAttribute.layoutAttribute;
276 | switch (layoutAttribute) {
277 | case NSLayoutAttributeCenterX:
278 | self.layoutConstant = centerOffset.x;
279 | break;
280 | case NSLayoutAttributeCenterY:
281 | self.layoutConstant = centerOffset.y;
282 | break;
283 | default:
284 | break;
285 | }
286 | }
287 |
288 | #pragma mark - MASConstraint
289 |
290 | - (void)activate {
291 | [self install];
292 | }
293 |
294 | - (void)deactivate {
295 | [self uninstall];
296 | }
297 |
298 | - (void)install {
299 | if (self.hasBeenInstalled) {
300 | return;
301 | }
302 |
303 | if ([self supportsActiveProperty] && self.layoutConstraint) {
304 | self.layoutConstraint.active = YES;
305 | [self.firstViewAttribute.view.mas_installedConstraints addObject:self];
306 | return;
307 | }
308 |
309 | MAS_VIEW *firstLayoutItem = self.firstViewAttribute.item;
310 | NSLayoutAttribute firstLayoutAttribute = self.firstViewAttribute.layoutAttribute;
311 | MAS_VIEW *secondLayoutItem = self.secondViewAttribute.item;
312 | NSLayoutAttribute secondLayoutAttribute = self.secondViewAttribute.layoutAttribute;
313 |
314 | // alignment attributes must have a secondViewAttribute
315 | // therefore we assume that is refering to superview
316 | // eg make.left.equalTo(@10)
317 | if (!self.firstViewAttribute.isSizeAttribute && !self.secondViewAttribute) {
318 | secondLayoutItem = self.firstViewAttribute.view.superview;
319 | secondLayoutAttribute = firstLayoutAttribute;
320 | }
321 |
322 | MASLayoutConstraint *layoutConstraint
323 | = [MASLayoutConstraint constraintWithItem:firstLayoutItem
324 | attribute:firstLayoutAttribute
325 | relatedBy:self.layoutRelation
326 | toItem:secondLayoutItem
327 | attribute:secondLayoutAttribute
328 | multiplier:self.layoutMultiplier
329 | constant:self.layoutConstant];
330 |
331 | layoutConstraint.priority = self.layoutPriority;
332 | layoutConstraint.mas_key = self.mas_key;
333 |
334 | if (self.secondViewAttribute.view) {
335 | MAS_VIEW *closestCommonSuperview = [self.firstViewAttribute.view mas_closestCommonSuperview:self.secondViewAttribute.view];
336 | NSAssert(closestCommonSuperview,
337 | @"couldn't find a common superview for %@ and %@",
338 | self.firstViewAttribute.view, self.secondViewAttribute.view);
339 | self.installedView = closestCommonSuperview;
340 | } else if (self.firstViewAttribute.isSizeAttribute) {
341 | self.installedView = self.firstViewAttribute.view;
342 | } else {
343 | self.installedView = self.firstViewAttribute.view.superview;
344 | }
345 |
346 |
347 | MASLayoutConstraint *existingConstraint = nil;
348 | if (self.updateExisting) {
349 | existingConstraint = [self layoutConstraintSimilarTo:layoutConstraint];
350 | }
351 | if (existingConstraint) {
352 | // just update the constant
353 | existingConstraint.constant = layoutConstraint.constant;
354 | self.layoutConstraint = existingConstraint;
355 | } else {
356 | [self.installedView addConstraint:layoutConstraint];
357 | self.layoutConstraint = layoutConstraint;
358 | [firstLayoutItem.mas_installedConstraints addObject:self];
359 | }
360 | }
361 |
362 | - (MASLayoutConstraint *)layoutConstraintSimilarTo:(MASLayoutConstraint *)layoutConstraint {
363 | // check if any constraints are the same apart from the only mutable property constant
364 |
365 | // go through constraints in reverse as we do not want to match auto-resizing or interface builder constraints
366 | // and they are likely to be added first.
367 | for (NSLayoutConstraint *existingConstraint in self.installedView.constraints.reverseObjectEnumerator) {
368 | if (![existingConstraint isKindOfClass:MASLayoutConstraint.class]) continue;
369 | if (existingConstraint.firstItem != layoutConstraint.firstItem) continue;
370 | if (existingConstraint.secondItem != layoutConstraint.secondItem) continue;
371 | if (existingConstraint.firstAttribute != layoutConstraint.firstAttribute) continue;
372 | if (existingConstraint.secondAttribute != layoutConstraint.secondAttribute) continue;
373 | if (existingConstraint.relation != layoutConstraint.relation) continue;
374 | if (existingConstraint.multiplier != layoutConstraint.multiplier) continue;
375 | if (existingConstraint.priority != layoutConstraint.priority) continue;
376 |
377 | return (id)existingConstraint;
378 | }
379 | return nil;
380 | }
381 |
382 | - (void)uninstall {
383 | if ([self supportsActiveProperty]) {
384 | self.layoutConstraint.active = NO;
385 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
386 | return;
387 | }
388 |
389 | [self.installedView removeConstraint:self.layoutConstraint];
390 | self.layoutConstraint = nil;
391 | self.installedView = nil;
392 |
393 | [self.firstViewAttribute.view.mas_installedConstraints removeObject:self];
394 | }
395 |
396 | @end
397 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/Masonry.h:
--------------------------------------------------------------------------------
1 | //
2 | // Masonry.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | //! Project version number for Masonry.
12 | FOUNDATION_EXPORT double MasonryVersionNumber;
13 |
14 | //! Project version string for Masonry.
15 | FOUNDATION_EXPORT const unsigned char MasonryVersionString[];
16 |
17 | #import "MASUtilities.h"
18 | #import "View+MASAdditions.h"
19 | #import "View+MASShorthandAdditions.h"
20 | #import "ViewController+MASAdditions.h"
21 | #import "NSArray+MASAdditions.h"
22 | #import "NSArray+MASShorthandAdditions.h"
23 | #import "MASConstraint.h"
24 | #import "MASCompositeConstraint.h"
25 | #import "MASViewAttribute.h"
26 | #import "MASViewConstraint.h"
27 | #import "MASConstraintMaker.h"
28 | #import "MASLayoutConstraint.h"
29 | #import "NSLayoutConstraint+MASDebugAdditions.h"
30 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/NSArray+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.h
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | typedef NS_ENUM(NSUInteger, MASAxisType) {
14 | MASAxisTypeHorizontal,
15 | MASAxisTypeVertical
16 | };
17 |
18 | @interface NSArray (MASAdditions)
19 |
20 | /**
21 | * Creates a MASConstraintMaker with each view in the callee.
22 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing on each view
23 | *
24 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
25 | *
26 | * @return Array of created MASConstraints
27 | */
28 | - (NSArray *)mas_makeConstraints:(void (^)(MASConstraintMaker *make))block;
29 |
30 | /**
31 | * Creates a MASConstraintMaker with each view in the callee.
32 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
33 | * If an existing constraint exists then it will be updated instead.
34 | *
35 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
36 | *
37 | * @return Array of created/updated MASConstraints
38 | */
39 | - (NSArray *)mas_updateConstraints:(void (^)(MASConstraintMaker *make))block;
40 |
41 | /**
42 | * Creates a MASConstraintMaker with each view in the callee.
43 | * Any constraints defined are added to each view or the appropriate superview once the block has finished executing on each view.
44 | * All constraints previously installed for the views will be removed.
45 | *
46 | * @param block scope within which you can build up the constraints which you wish to apply to each view.
47 | *
48 | * @return Array of created/updated MASConstraints
49 | */
50 | - (NSArray *)mas_remakeConstraints:(void (^)(MASConstraintMaker *make))block;
51 |
52 | /**
53 | * distribute with fixed spacing
54 | *
55 | * @param axisType which axis to distribute items along
56 | * @param fixedSpacing the spacing between each item
57 | * @param leadSpacing the spacing before the first item and the container
58 | * @param tailSpacing the spacing after the last item and the container
59 | */
60 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
61 |
62 | /**
63 | * distribute with fixed item size
64 | *
65 | * @param axisType which axis to distribute items along
66 | * @param fixedItemLength the fixed length of each item
67 | * @param leadSpacing the spacing before the first item and the container
68 | * @param tailSpacing the spacing after the last item and the container
69 | */
70 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing;
71 |
72 | @end
73 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/NSArray+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASAdditions.m
3 | //
4 | //
5 | // Created by Daniel Hammond on 11/26/13.
6 | //
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 | #import "View+MASAdditions.h"
11 |
12 | @implementation NSArray (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block {
15 | NSMutableArray *constraints = [NSMutableArray array];
16 | for (MAS_VIEW *view in self) {
17 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
18 | [constraints addObjectsFromArray:[view mas_makeConstraints:block]];
19 | }
20 | return constraints;
21 | }
22 |
23 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block {
24 | NSMutableArray *constraints = [NSMutableArray array];
25 | for (MAS_VIEW *view in self) {
26 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
27 | [constraints addObjectsFromArray:[view mas_updateConstraints:block]];
28 | }
29 | return constraints;
30 | }
31 |
32 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
33 | NSMutableArray *constraints = [NSMutableArray array];
34 | for (MAS_VIEW *view in self) {
35 | NSAssert([view isKindOfClass:[MAS_VIEW class]], @"All objects in the array must be views");
36 | [constraints addObjectsFromArray:[view mas_remakeConstraints:block]];
37 | }
38 | return constraints;
39 | }
40 |
41 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedSpacing:(CGFloat)fixedSpacing leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing {
42 | if (self.count < 2) {
43 | NSAssert(self.count>1,@"views to distribute need to bigger than one");
44 | return;
45 | }
46 |
47 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews];
48 | if (axisType == MASAxisTypeHorizontal) {
49 | MAS_VIEW *prev;
50 | for (int i = 0; i < self.count; i++) {
51 | MAS_VIEW *v = self[i];
52 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
53 | if (prev) {
54 | make.width.equalTo(prev);
55 | make.left.equalTo(prev.mas_right).offset(fixedSpacing);
56 | if (i == self.count - 1) {//last one
57 | make.right.equalTo(tempSuperView).offset(-tailSpacing);
58 | }
59 | }
60 | else {//first one
61 | make.left.equalTo(tempSuperView).offset(leadSpacing);
62 | }
63 |
64 | }];
65 | prev = v;
66 | }
67 | }
68 | else {
69 | MAS_VIEW *prev;
70 | for (int i = 0; i < self.count; i++) {
71 | MAS_VIEW *v = self[i];
72 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
73 | if (prev) {
74 | make.height.equalTo(prev);
75 | make.top.equalTo(prev.mas_bottom).offset(fixedSpacing);
76 | if (i == self.count - 1) {//last one
77 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing);
78 | }
79 | }
80 | else {//first one
81 | make.top.equalTo(tempSuperView).offset(leadSpacing);
82 | }
83 |
84 | }];
85 | prev = v;
86 | }
87 | }
88 | }
89 |
90 | - (void)mas_distributeViewsAlongAxis:(MASAxisType)axisType withFixedItemLength:(CGFloat)fixedItemLength leadSpacing:(CGFloat)leadSpacing tailSpacing:(CGFloat)tailSpacing {
91 | if (self.count < 2) {
92 | NSAssert(self.count>1,@"views to distribute need to bigger than one");
93 | return;
94 | }
95 |
96 | MAS_VIEW *tempSuperView = [self mas_commonSuperviewOfViews];
97 | if (axisType == MASAxisTypeHorizontal) {
98 | MAS_VIEW *prev;
99 | for (int i = 0; i < self.count; i++) {
100 | MAS_VIEW *v = self[i];
101 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
102 | if (prev) {
103 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
104 | make.width.equalTo(@(fixedItemLength));
105 | if (i == self.count - 1) {//last one
106 | make.right.equalTo(tempSuperView).offset(-tailSpacing);
107 | }
108 | else {
109 | make.right.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
110 | }
111 | }
112 | else {//first one
113 | make.left.equalTo(tempSuperView).offset(leadSpacing);
114 | make.width.equalTo(@(fixedItemLength));
115 | }
116 | }];
117 | prev = v;
118 | }
119 | }
120 | else {
121 | MAS_VIEW *prev;
122 | for (int i = 0; i < self.count; i++) {
123 | MAS_VIEW *v = self[i];
124 | [v mas_makeConstraints:^(MASConstraintMaker *make) {
125 | if (prev) {
126 | CGFloat offset = (1-(i/((CGFloat)self.count-1)))*(fixedItemLength+leadSpacing)-i*tailSpacing/(((CGFloat)self.count-1));
127 | make.height.equalTo(@(fixedItemLength));
128 | if (i == self.count - 1) {//last one
129 | make.bottom.equalTo(tempSuperView).offset(-tailSpacing);
130 | }
131 | else {
132 | make.bottom.equalTo(tempSuperView).multipliedBy(i/((CGFloat)self.count-1)).with.offset(offset);
133 | }
134 | }
135 | else {//first one
136 | make.top.equalTo(tempSuperView).offset(leadSpacing);
137 | make.height.equalTo(@(fixedItemLength));
138 | }
139 | }];
140 | prev = v;
141 | }
142 | }
143 | }
144 |
145 | - (MAS_VIEW *)mas_commonSuperviewOfViews
146 | {
147 | MAS_VIEW *commonSuperview = nil;
148 | MAS_VIEW *previousView = nil;
149 | for (id object in self) {
150 | if ([object isKindOfClass:[MAS_VIEW class]]) {
151 | MAS_VIEW *view = (MAS_VIEW *)object;
152 | if (previousView) {
153 | commonSuperview = [view mas_closestCommonSuperview:commonSuperview];
154 | } else {
155 | commonSuperview = view;
156 | }
157 | previousView = view;
158 | }
159 | }
160 | NSAssert(commonSuperview, @"Can't constrain views that do not share a common superview. Make sure that all the views in this array have been added into the same view hierarchy.");
161 | return commonSuperview;
162 | }
163 |
164 | @end
165 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/NSArray+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSArray+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSArray+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand array additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface NSArray (MASShorthandAdditions)
18 |
19 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
20 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
21 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
22 |
23 | @end
24 |
25 | @implementation NSArray (MASShorthandAdditions)
26 |
27 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
28 | return [self mas_makeConstraints:block];
29 | }
30 |
31 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
32 | return [self mas_updateConstraints:block];
33 | }
34 |
35 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
36 | return [self mas_remakeConstraints:block];
37 | }
38 |
39 | @end
40 |
41 | #endif
42 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/NSLayoutConstraint+MASDebugAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 |
11 | /**
12 | * makes debug and log output of NSLayoutConstraints more readable
13 | */
14 | @interface NSLayoutConstraint (MASDebugAdditions)
15 |
16 | @end
17 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/NSLayoutConstraint+MASDebugAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // NSLayoutConstraint+MASDebugAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 3/08/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "NSLayoutConstraint+MASDebugAdditions.h"
10 | #import "MASConstraint.h"
11 | #import "MASLayoutConstraint.h"
12 |
13 | @implementation NSLayoutConstraint (MASDebugAdditions)
14 |
15 | #pragma mark - description maps
16 |
17 | + (NSDictionary *)layoutRelationDescriptionsByValue {
18 | static dispatch_once_t once;
19 | static NSDictionary *descriptionMap;
20 | dispatch_once(&once, ^{
21 | descriptionMap = @{
22 | @(NSLayoutRelationEqual) : @"==",
23 | @(NSLayoutRelationGreaterThanOrEqual) : @">=",
24 | @(NSLayoutRelationLessThanOrEqual) : @"<=",
25 | };
26 | });
27 | return descriptionMap;
28 | }
29 |
30 | + (NSDictionary *)layoutAttributeDescriptionsByValue {
31 | static dispatch_once_t once;
32 | static NSDictionary *descriptionMap;
33 | dispatch_once(&once, ^{
34 | descriptionMap = @{
35 | @(NSLayoutAttributeTop) : @"top",
36 | @(NSLayoutAttributeLeft) : @"left",
37 | @(NSLayoutAttributeBottom) : @"bottom",
38 | @(NSLayoutAttributeRight) : @"right",
39 | @(NSLayoutAttributeLeading) : @"leading",
40 | @(NSLayoutAttributeTrailing) : @"trailing",
41 | @(NSLayoutAttributeWidth) : @"width",
42 | @(NSLayoutAttributeHeight) : @"height",
43 | @(NSLayoutAttributeCenterX) : @"centerX",
44 | @(NSLayoutAttributeCenterY) : @"centerY",
45 | @(NSLayoutAttributeBaseline) : @"baseline",
46 |
47 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
48 | @(NSLayoutAttributeFirstBaseline) : @"firstBaseline",
49 | @(NSLayoutAttributeLastBaseline) : @"lastBaseline",
50 | #endif
51 |
52 | #if TARGET_OS_IPHONE || TARGET_OS_TV
53 | @(NSLayoutAttributeLeftMargin) : @"leftMargin",
54 | @(NSLayoutAttributeRightMargin) : @"rightMargin",
55 | @(NSLayoutAttributeTopMargin) : @"topMargin",
56 | @(NSLayoutAttributeBottomMargin) : @"bottomMargin",
57 | @(NSLayoutAttributeLeadingMargin) : @"leadingMargin",
58 | @(NSLayoutAttributeTrailingMargin) : @"trailingMargin",
59 | @(NSLayoutAttributeCenterXWithinMargins) : @"centerXWithinMargins",
60 | @(NSLayoutAttributeCenterYWithinMargins) : @"centerYWithinMargins",
61 | #endif
62 |
63 | };
64 |
65 | });
66 | return descriptionMap;
67 | }
68 |
69 |
70 | + (NSDictionary *)layoutPriorityDescriptionsByValue {
71 | static dispatch_once_t once;
72 | static NSDictionary *descriptionMap;
73 | dispatch_once(&once, ^{
74 | #if TARGET_OS_IPHONE || TARGET_OS_TV
75 | descriptionMap = @{
76 | @(MASLayoutPriorityDefaultHigh) : @"high",
77 | @(MASLayoutPriorityDefaultLow) : @"low",
78 | @(MASLayoutPriorityDefaultMedium) : @"medium",
79 | @(MASLayoutPriorityRequired) : @"required",
80 | @(MASLayoutPriorityFittingSizeLevel) : @"fitting size",
81 | };
82 | #elif TARGET_OS_MAC
83 | descriptionMap = @{
84 | @(MASLayoutPriorityDefaultHigh) : @"high",
85 | @(MASLayoutPriorityDragThatCanResizeWindow) : @"drag can resize window",
86 | @(MASLayoutPriorityDefaultMedium) : @"medium",
87 | @(MASLayoutPriorityWindowSizeStayPut) : @"window size stay put",
88 | @(MASLayoutPriorityDragThatCannotResizeWindow) : @"drag cannot resize window",
89 | @(MASLayoutPriorityDefaultLow) : @"low",
90 | @(MASLayoutPriorityFittingSizeCompression) : @"fitting size",
91 | @(MASLayoutPriorityRequired) : @"required",
92 | };
93 | #endif
94 | });
95 | return descriptionMap;
96 | }
97 |
98 | #pragma mark - description override
99 |
100 | + (NSString *)descriptionForObject:(id)obj {
101 | if ([obj respondsToSelector:@selector(mas_key)] && [obj mas_key]) {
102 | return [NSString stringWithFormat:@"%@:%@", [obj class], [obj mas_key]];
103 | }
104 | return [NSString stringWithFormat:@"%@:%p", [obj class], obj];
105 | }
106 |
107 | - (NSString *)description {
108 | NSMutableString *description = [[NSMutableString alloc] initWithString:@"<"];
109 |
110 | [description appendString:[self.class descriptionForObject:self]];
111 |
112 | [description appendFormat:@" %@", [self.class descriptionForObject:self.firstItem]];
113 | if (self.firstAttribute != NSLayoutAttributeNotAnAttribute) {
114 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.firstAttribute)]];
115 | }
116 |
117 | [description appendFormat:@" %@", self.class.layoutRelationDescriptionsByValue[@(self.relation)]];
118 |
119 | if (self.secondItem) {
120 | [description appendFormat:@" %@", [self.class descriptionForObject:self.secondItem]];
121 | }
122 | if (self.secondAttribute != NSLayoutAttributeNotAnAttribute) {
123 | [description appendFormat:@".%@", self.class.layoutAttributeDescriptionsByValue[@(self.secondAttribute)]];
124 | }
125 |
126 | if (self.multiplier != 1) {
127 | [description appendFormat:@" * %g", self.multiplier];
128 | }
129 |
130 | if (self.secondAttribute == NSLayoutAttributeNotAnAttribute) {
131 | [description appendFormat:@" %g", self.constant];
132 | } else {
133 | if (self.constant) {
134 | [description appendFormat:@" %@ %g", (self.constant < 0 ? @"-" : @"+"), ABS(self.constant)];
135 | }
136 | }
137 |
138 | if (self.priority != MASLayoutPriorityRequired) {
139 | [description appendFormat:@" ^%@", self.class.layoutPriorityDescriptionsByValue[@(self.priority)] ?: [NSNumber numberWithDouble:self.priority]];
140 | }
141 |
142 | [description appendString:@">"];
143 | return description;
144 | }
145 |
146 | @end
147 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/View+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | /**
14 | * Provides constraint maker block
15 | * and convience methods for creating MASViewAttribute which are view + NSLayoutAttribute pairs
16 | */
17 | @interface MAS_VIEW (MASAdditions)
18 |
19 | /**
20 | * following properties return a new MASViewAttribute with current view and appropriate NSLayoutAttribute
21 | */
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_left;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_top;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_right;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottom;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leading;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailing;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_width;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_height;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerX;
31 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerY;
32 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_baseline;
33 | @property (nonatomic, strong, readonly) MASViewAttribute *(^mas_attribute)(NSLayoutAttribute attr);
34 |
35 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
36 |
37 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_firstBaseline;
38 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_lastBaseline;
39 |
40 | #endif
41 |
42 | #if TARGET_OS_IPHONE || TARGET_OS_TV
43 |
44 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leftMargin;
45 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_rightMargin;
46 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topMargin;
47 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomMargin;
48 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_leadingMargin;
49 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_trailingMargin;
50 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerXWithinMargins;
51 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_centerYWithinMargins;
52 |
53 | #endif
54 |
55 | /**
56 | * a key to associate with this view
57 | */
58 | @property (nonatomic, strong) id mas_key;
59 |
60 | /**
61 | * Finds the closest common superview between this view and another view
62 | *
63 | * @param view other view
64 | *
65 | * @return returns nil if common superview could not be found
66 | */
67 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view;
68 |
69 | /**
70 | * Creates a MASConstraintMaker with the callee view.
71 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing
72 | *
73 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
74 | *
75 | * @return Array of created MASConstraints
76 | */
77 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *make))block;
78 |
79 | /**
80 | * Creates a MASConstraintMaker with the callee view.
81 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
82 | * If an existing constraint exists then it will be updated instead.
83 | *
84 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
85 | *
86 | * @return Array of created/updated MASConstraints
87 | */
88 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *make))block;
89 |
90 | /**
91 | * Creates a MASConstraintMaker with the callee view.
92 | * Any constraints defined are added to the view or the appropriate superview once the block has finished executing.
93 | * All constraints previously installed for the view will be removed.
94 | *
95 | * @param block scope within which you can build up the constraints which you wish to apply to the view.
96 | *
97 | * @return Array of created/updated MASConstraints
98 | */
99 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block;
100 |
101 | @end
102 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/View+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 20/07/13.
6 | // Copyright (c) 2013 cloudling. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 | #import
11 |
12 | @implementation MAS_VIEW (MASAdditions)
13 |
14 | - (NSArray *)mas_makeConstraints:(void(^)(MASConstraintMaker *))block {
15 | self.translatesAutoresizingMaskIntoConstraints = NO;
16 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
17 | block(constraintMaker);
18 | return [constraintMaker install];
19 | }
20 |
21 | - (NSArray *)mas_updateConstraints:(void(^)(MASConstraintMaker *))block {
22 | self.translatesAutoresizingMaskIntoConstraints = NO;
23 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
24 | constraintMaker.updateExisting = YES;
25 | block(constraintMaker);
26 | return [constraintMaker install];
27 | }
28 |
29 | - (NSArray *)mas_remakeConstraints:(void(^)(MASConstraintMaker *make))block {
30 | self.translatesAutoresizingMaskIntoConstraints = NO;
31 | MASConstraintMaker *constraintMaker = [[MASConstraintMaker alloc] initWithView:self];
32 | constraintMaker.removeExisting = YES;
33 | block(constraintMaker);
34 | return [constraintMaker install];
35 | }
36 |
37 | #pragma mark - NSLayoutAttribute properties
38 |
39 | - (MASViewAttribute *)mas_left {
40 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeft];
41 | }
42 |
43 | - (MASViewAttribute *)mas_top {
44 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTop];
45 | }
46 |
47 | - (MASViewAttribute *)mas_right {
48 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRight];
49 | }
50 |
51 | - (MASViewAttribute *)mas_bottom {
52 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottom];
53 | }
54 |
55 | - (MASViewAttribute *)mas_leading {
56 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeading];
57 | }
58 |
59 | - (MASViewAttribute *)mas_trailing {
60 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailing];
61 | }
62 |
63 | - (MASViewAttribute *)mas_width {
64 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeWidth];
65 | }
66 |
67 | - (MASViewAttribute *)mas_height {
68 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeHeight];
69 | }
70 |
71 | - (MASViewAttribute *)mas_centerX {
72 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterX];
73 | }
74 |
75 | - (MASViewAttribute *)mas_centerY {
76 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterY];
77 | }
78 |
79 | - (MASViewAttribute *)mas_baseline {
80 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBaseline];
81 | }
82 |
83 | - (MASViewAttribute *(^)(NSLayoutAttribute))mas_attribute
84 | {
85 | return ^(NSLayoutAttribute attr) {
86 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:attr];
87 | };
88 | }
89 |
90 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
91 |
92 | - (MASViewAttribute *)mas_firstBaseline {
93 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeFirstBaseline];
94 | }
95 | - (MASViewAttribute *)mas_lastBaseline {
96 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLastBaseline];
97 | }
98 |
99 | #endif
100 |
101 | #if TARGET_OS_IPHONE || TARGET_OS_TV
102 |
103 | - (MASViewAttribute *)mas_leftMargin {
104 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeftMargin];
105 | }
106 |
107 | - (MASViewAttribute *)mas_rightMargin {
108 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeRightMargin];
109 | }
110 |
111 | - (MASViewAttribute *)mas_topMargin {
112 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTopMargin];
113 | }
114 |
115 | - (MASViewAttribute *)mas_bottomMargin {
116 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeBottomMargin];
117 | }
118 |
119 | - (MASViewAttribute *)mas_leadingMargin {
120 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeLeadingMargin];
121 | }
122 |
123 | - (MASViewAttribute *)mas_trailingMargin {
124 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeTrailingMargin];
125 | }
126 |
127 | - (MASViewAttribute *)mas_centerXWithinMargins {
128 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterXWithinMargins];
129 | }
130 |
131 | - (MASViewAttribute *)mas_centerYWithinMargins {
132 | return [[MASViewAttribute alloc] initWithView:self layoutAttribute:NSLayoutAttributeCenterYWithinMargins];
133 | }
134 |
135 | #endif
136 |
137 | #pragma mark - associated properties
138 |
139 | - (id)mas_key {
140 | return objc_getAssociatedObject(self, @selector(mas_key));
141 | }
142 |
143 | - (void)setMas_key:(id)key {
144 | objc_setAssociatedObject(self, @selector(mas_key), key, OBJC_ASSOCIATION_RETAIN_NONATOMIC);
145 | }
146 |
147 | #pragma mark - heirachy
148 |
149 | - (instancetype)mas_closestCommonSuperview:(MAS_VIEW *)view {
150 | MAS_VIEW *closestCommonSuperview = nil;
151 |
152 | MAS_VIEW *secondViewSuperview = view;
153 | while (!closestCommonSuperview && secondViewSuperview) {
154 | MAS_VIEW *firstViewSuperview = self;
155 | while (!closestCommonSuperview && firstViewSuperview) {
156 | if (secondViewSuperview == firstViewSuperview) {
157 | closestCommonSuperview = secondViewSuperview;
158 | }
159 | firstViewSuperview = firstViewSuperview.superview;
160 | }
161 | secondViewSuperview = secondViewSuperview.superview;
162 | }
163 | return closestCommonSuperview;
164 | }
165 |
166 | @end
167 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/View+MASShorthandAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIView+MASShorthandAdditions.h
3 | // Masonry
4 | //
5 | // Created by Jonas Budelmann on 22/07/13.
6 | // Copyright (c) 2013 Jonas Budelmann. All rights reserved.
7 | //
8 |
9 | #import "View+MASAdditions.h"
10 |
11 | #ifdef MAS_SHORTHAND
12 |
13 | /**
14 | * Shorthand view additions without the 'mas_' prefixes,
15 | * only enabled if MAS_SHORTHAND is defined
16 | */
17 | @interface MAS_VIEW (MASShorthandAdditions)
18 |
19 | @property (nonatomic, strong, readonly) MASViewAttribute *left;
20 | @property (nonatomic, strong, readonly) MASViewAttribute *top;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *right;
22 | @property (nonatomic, strong, readonly) MASViewAttribute *bottom;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *leading;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *trailing;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *width;
26 | @property (nonatomic, strong, readonly) MASViewAttribute *height;
27 | @property (nonatomic, strong, readonly) MASViewAttribute *centerX;
28 | @property (nonatomic, strong, readonly) MASViewAttribute *centerY;
29 | @property (nonatomic, strong, readonly) MASViewAttribute *baseline;
30 | @property (nonatomic, strong, readonly) MASViewAttribute *(^attribute)(NSLayoutAttribute attr);
31 |
32 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
33 |
34 | @property (nonatomic, strong, readonly) MASViewAttribute *firstBaseline;
35 | @property (nonatomic, strong, readonly) MASViewAttribute *lastBaseline;
36 |
37 | #endif
38 |
39 | #if TARGET_OS_IPHONE || TARGET_OS_TV
40 |
41 | @property (nonatomic, strong, readonly) MASViewAttribute *leftMargin;
42 | @property (nonatomic, strong, readonly) MASViewAttribute *rightMargin;
43 | @property (nonatomic, strong, readonly) MASViewAttribute *topMargin;
44 | @property (nonatomic, strong, readonly) MASViewAttribute *bottomMargin;
45 | @property (nonatomic, strong, readonly) MASViewAttribute *leadingMargin;
46 | @property (nonatomic, strong, readonly) MASViewAttribute *trailingMargin;
47 | @property (nonatomic, strong, readonly) MASViewAttribute *centerXWithinMargins;
48 | @property (nonatomic, strong, readonly) MASViewAttribute *centerYWithinMargins;
49 |
50 | #endif
51 |
52 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *make))block;
53 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *make))block;
54 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *make))block;
55 |
56 | @end
57 |
58 | #define MAS_ATTR_FORWARD(attr) \
59 | - (MASViewAttribute *)attr { \
60 | return [self mas_##attr]; \
61 | }
62 |
63 | @implementation MAS_VIEW (MASShorthandAdditions)
64 |
65 | MAS_ATTR_FORWARD(top);
66 | MAS_ATTR_FORWARD(left);
67 | MAS_ATTR_FORWARD(bottom);
68 | MAS_ATTR_FORWARD(right);
69 | MAS_ATTR_FORWARD(leading);
70 | MAS_ATTR_FORWARD(trailing);
71 | MAS_ATTR_FORWARD(width);
72 | MAS_ATTR_FORWARD(height);
73 | MAS_ATTR_FORWARD(centerX);
74 | MAS_ATTR_FORWARD(centerY);
75 | MAS_ATTR_FORWARD(baseline);
76 |
77 | #if (__IPHONE_OS_VERSION_MIN_REQUIRED >= 80000) || (__TV_OS_VERSION_MIN_REQUIRED >= 9000) || (__MAC_OS_X_VERSION_MIN_REQUIRED >= 101100)
78 |
79 | MAS_ATTR_FORWARD(firstBaseline);
80 | MAS_ATTR_FORWARD(lastBaseline);
81 |
82 | #endif
83 |
84 | #if TARGET_OS_IPHONE || TARGET_OS_TV
85 |
86 | MAS_ATTR_FORWARD(leftMargin);
87 | MAS_ATTR_FORWARD(rightMargin);
88 | MAS_ATTR_FORWARD(topMargin);
89 | MAS_ATTR_FORWARD(bottomMargin);
90 | MAS_ATTR_FORWARD(leadingMargin);
91 | MAS_ATTR_FORWARD(trailingMargin);
92 | MAS_ATTR_FORWARD(centerXWithinMargins);
93 | MAS_ATTR_FORWARD(centerYWithinMargins);
94 |
95 | #endif
96 |
97 | - (MASViewAttribute *(^)(NSLayoutAttribute))attribute {
98 | return [self mas_attribute];
99 | }
100 |
101 | - (NSArray *)makeConstraints:(void(^)(MASConstraintMaker *))block {
102 | return [self mas_makeConstraints:block];
103 | }
104 |
105 | - (NSArray *)updateConstraints:(void(^)(MASConstraintMaker *))block {
106 | return [self mas_updateConstraints:block];
107 | }
108 |
109 | - (NSArray *)remakeConstraints:(void(^)(MASConstraintMaker *))block {
110 | return [self mas_remakeConstraints:block];
111 | }
112 |
113 | @end
114 |
115 | #endif
116 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/ViewController+MASAdditions.h:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.h
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "MASUtilities.h"
10 | #import "MASConstraintMaker.h"
11 | #import "MASViewAttribute.h"
12 |
13 | #ifdef MAS_VIEW_CONTROLLER
14 |
15 | @interface MAS_VIEW_CONTROLLER (MASAdditions)
16 |
17 | /**
18 | * following properties return a new MASViewAttribute with appropriate UILayoutGuide and NSLayoutAttribute
19 | */
20 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuide;
21 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuide;
22 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideTop;
23 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_topLayoutGuideBottom;
24 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideTop;
25 | @property (nonatomic, strong, readonly) MASViewAttribute *mas_bottomLayoutGuideBottom;
26 |
27 |
28 | @end
29 |
30 | #endif
31 |
--------------------------------------------------------------------------------
/SCN3DPlayer/Masonry/ViewController+MASAdditions.m:
--------------------------------------------------------------------------------
1 | //
2 | // UIViewController+MASAdditions.m
3 | // Masonry
4 | //
5 | // Created by Craig Siemens on 2015-06-23.
6 | //
7 | //
8 |
9 | #import "ViewController+MASAdditions.h"
10 |
11 | #ifdef MAS_VIEW_CONTROLLER
12 |
13 | @implementation MAS_VIEW_CONTROLLER (MASAdditions)
14 |
15 | - (MASViewAttribute *)mas_topLayoutGuide {
16 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
17 | }
18 | - (MASViewAttribute *)mas_topLayoutGuideTop {
19 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeTop];
20 | }
21 | - (MASViewAttribute *)mas_topLayoutGuideBottom {
22 | return [[MASViewAttribute alloc] initWithView:self.view item:self.topLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
23 | }
24 |
25 | - (MASViewAttribute *)mas_bottomLayoutGuide {
26 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop];
27 | }
28 | - (MASViewAttribute *)mas_bottomLayoutGuideTop {
29 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeTop];
30 | }
31 | - (MASViewAttribute *)mas_bottomLayoutGuideBottom {
32 | return [[MASViewAttribute alloc] initWithView:self.view item:self.bottomLayoutGuide layoutAttribute:NSLayoutAttributeBottom];
33 | }
34 |
35 |
36 |
37 | @end
38 |
39 | #endif
40 |
--------------------------------------------------------------------------------
/SCN3DPlayer/SCN3DPlayer/SCN3DPlayerView.h:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DPlayerView.h
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 | #import
12 |
13 |
14 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
15 |
16 | /**
17 | 触摸,重力,触摸重力
18 |
19 | - SCN3DInteractive_Touch: 触摸
20 | - SCN3DInteractive_Motion: 重力
21 | - SCN3DInteractive_MotionAndTouch: 触摸和重力
22 | */
23 | typedef NS_ENUM(NSInteger, SCN3DInteractive_) {
24 | SCN3DInteractive_Touch,
25 | SCN3DInteractive_Motion,
26 | SCN3DInteractive_MotionAndTouch,
27 | };
28 |
29 | /**
30 | 形状模式枚举
31 |
32 | - SCN3DDisplayMode_Plane_Normal: 普通模式
33 | - SCN3DDisplayMode_Plane_Slide: 平面180模式
34 | - SCN3DDisplayMode_Tube: 圆柱模式
35 | - SCN3DDisplayMode_Sphere: 球模式
36 | - SCN3DDisplayMode_VR360: 全景模式
37 | - SCN3DDisplayMode_VRGlass: VR双屏模式
38 | */
39 | typedef NS_ENUM(NSUInteger, SCN3DDisplayMode_) {
40 | SCN3DDisplayMode_Plane_Normal = 0,
41 | SCN3DDisplayMode_Plane_Slide,
42 | SCN3DDisplayMode_Tube,
43 | SCN3DDisplayMode_Sphere,
44 | SCN3DDisplayMode_VR360,
45 | SCN3DDisplayMode_VRGlass,
46 | };
47 |
48 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
49 |
50 | @interface SCN3DPlayerView : UIView
51 |
52 | @property (nonatomic, strong) SCNScene *scene;
53 | @property (nonatomic, strong) SCNView *scViewLeft;
54 | @property (nonatomic, strong) SCNView *scViewRight;
55 | @property (nonatomic, strong) SCNNode *shapeNode;
56 | @property (nonatomic, strong) SCNNode *cameraNode;
57 |
58 | //_________________________________________________________________________________________________
59 |
60 | /**
61 | 设置使用重力,还是手指触摸,或者两者都持
62 |
63 | @param interactive SCN3DInteractive_ 枚举参数
64 | */
65 | - (void)setInteractiveMode:(SCN3DInteractive_)interactive;
66 |
67 | /**
68 | 设置sceneKit 渲染模式,有Vr ,全景,等等模式
69 |
70 | @param displayMode SCN3DDisplayMode_ 枚举参数
71 | */
72 | - (void)setVideoDisplayMode:(SCN3DDisplayMode_)displayMode;
73 |
74 | /**
75 | 是否,水平启用,垂直启用
76 |
77 | @param horEnabled Yes or no
78 | @param verEnabled yes or no
79 | */
80 | - (void)setHorizontalEnabled:(BOOL)horEnabled verticalEnabled:(BOOL)verEnabled;
81 |
82 | //是否开启重力传感器
83 | - (void)setGSensorMotionEnabled:(BOOL)GSensorEnabled;
84 | //是否开启缩放功能
85 | - (void)setPinchScaleEnabled:(BOOL)pinchEnabled;
86 | //设置缩放范围
87 | - (void)setMinScale:(float)minScale maxScale:(float)maxScale;
88 | //设置旋转范围
89 | - (void)setVerticalMinRotate:(float)minRotate maxRotate:(float)maxRotate;
90 | //设置纹理坐标平移
91 | - (void)setTextureOffsetX:(float)x offsetY:(float)y;
92 | //设置纹理坐标缩放
93 | - (void)setTextureScaleX:(float)x ScaleY:(float)y;
94 |
95 | //_________________________________________________________________________________________________
96 | //设置宽高比
97 | - (void)setVideoAspectRatio:(float)aspectRatio;
98 | //设置当前横屏或者竖屏
99 | - (void)setCurrentOrientation:(UIInterfaceOrientation)orientation;
100 | //设置当前缩放比例
101 | - (void)setCurrentScale:(float)curScale;
102 | //设置当前旋转角度
103 | - (void)setCurrentRotateX:(float)rotateX rotateY:(float)rotateY;
104 |
105 | //_________________________________________________________________________________________________
106 | //设置帧视频图像
107 | - (void)setFramesPerVideoImage:(UIImage *)image;
108 |
109 | @end
110 |
--------------------------------------------------------------------------------
/SCN3DPlayer/SCN3DPlayer/SCN3DPlayerView.m:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DPlayerView.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import "SCN3DPlayerView.h"
10 | #import
11 |
12 | @interface SCN3DPlayerView ()
13 |
14 | @property (nonatomic, assign) float rotateX;
15 | @property (nonatomic, assign) float rotateY;
16 | @property (nonatomic, assign) float minRotateX;
17 | @property (nonatomic, assign) float maxRotateX;
18 | @property (nonatomic, assign) float minScale;
19 | @property (nonatomic, assign) float maxScale;
20 | @property (nonatomic, assign) float curScale;
21 | @property (nonatomic, assign) float prevScale;
22 | @property (nonatomic, assign) float videoAspRatio;
23 | @property (nonatomic, assign) BOOL pinchEnabled;
24 | @property (nonatomic, assign) BOOL horizontalEnabled;
25 | @property (nonatomic, assign) BOOL verticalEnabled;
26 | @property (nonatomic, assign) BOOL GSensorEnabled;
27 | @property (nonatomic, assign) SCN3DInteractive_ interactive;
28 | @property (nonatomic, assign) SCN3DDisplayMode_ displayMode;
29 | @property (nonatomic, assign) SCNMatrix4 modelMatrix;
30 | @property (nonatomic, strong) CMMotionManager *motionManager;
31 | @property (nonatomic, assign) UIInterfaceOrientation orientation;
32 |
33 | @end
34 |
35 | @implementation SCN3DPlayerView
36 |
37 | - (id)initWithFrame:(CGRect)frame {
38 | if (self = [super initWithFrame:frame]) {
39 | [self initScene];
40 | }
41 | return self;
42 | }
43 |
44 | - (void)setFrame:(CGRect)frame {
45 | [super setFrame:frame];
46 | if (self.displayMode == SCN3DDisplayMode_VRGlass) {
47 | self.scViewLeft.frame = CGRectMake(0, 0, self.frame.size.width / 2, self.frame.size.height);
48 | self.scViewRight.frame = CGRectMake(self.frame.size.width / 2, 0, self.frame.size.width / 2, self.frame.size.height);
49 | }
50 | else {
51 | self.scViewLeft.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
52 | }
53 | }
54 |
55 | - (void)setBackgroundColor:(UIColor *)backgroundColor {
56 | [super setBackgroundColor:backgroundColor];
57 | self.scViewLeft.backgroundColor = backgroundColor;
58 | self.scViewRight.backgroundColor = backgroundColor;
59 | }
60 |
61 | - (void)initScene {
62 | self.scene = [SCNScene scene];
63 | self.scViewLeft = [[SCNView alloc] initWithFrame:CGRectMake(0, 0, self.frame.size.width, self.frame.size.height) options:nil];
64 | self.scViewLeft.backgroundColor = [UIColor blackColor];
65 | self.scViewLeft.scene = self.scene;
66 | self.scViewLeft.antialiasingMode = SCNAntialiasingModeMultisampling4X;
67 | [self addSubview:self.scViewLeft];
68 |
69 | self.cameraNode = [SCNNode node];
70 | self.cameraNode.camera = [SCNCamera camera];
71 | [self.scene.rootNode addChildNode:self.cameraNode];
72 |
73 | UIPinchGestureRecognizer *pinchGestureRecognizer = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchScale:)];
74 | [self addGestureRecognizer:pinchGestureRecognizer];
75 | }
76 |
77 | - (void)initSceneNodeWithMode:(SCN3DDisplayMode_)displayMode {
78 | [self.shapeNode removeFromParentNode];
79 | [self.scViewRight removeFromSuperview];
80 | [self initParameterSetting];
81 | switch (displayMode) {
82 | case SCN3DDisplayMode_Plane_Normal: {
83 | float width = 2.0;
84 | float height = width / self.videoAspRatio;
85 | self.shapeNode = [SCNNode nodeWithGeometry:[SCNPlane planeWithWidth:width height:height]];
86 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeClamp;
87 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeClamp;
88 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullBack;
89 | self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
90 | self.cameraNode.camera.usesOrthographicProjection = YES;
91 | }
92 | break;
93 | case SCN3DDisplayMode_Plane_Slide: {
94 | float width = 2.0;
95 | float height = width / self.videoAspRatio;
96 | self.shapeNode = [SCNNode nodeWithGeometry:[SCNPlane planeWithWidth:width height:height]];
97 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeRepeat;
98 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeRepeat;
99 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullBack;
100 | self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
101 | self.cameraNode.camera.usesOrthographicProjection = YES;
102 |
103 | }
104 | break;
105 | case SCN3DDisplayMode_Tube: {
106 | SCNTube *tube = [SCNTube tubeWithInnerRadius:1.0 outerRadius:1.0 height:1.0];
107 | tube.radialSegmentCount = 96;
108 | self.shapeNode = [SCNNode nodeWithGeometry:tube];
109 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeClamp;
110 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeClamp;
111 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullBack;
112 |
113 | self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
114 | self.cameraNode.camera.usesOrthographicProjection = YES;
115 | }
116 | break;
117 | case SCN3DDisplayMode_Sphere: {
118 |
119 | SCNSphere *sphere = [SCNSphere sphereWithRadius:1.0];
120 | sphere.segmentCount = 96;
121 | self.shapeNode = [SCNNode nodeWithGeometry:sphere];
122 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeClamp;
123 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeClamp;
124 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullBack;// 设置剔除内表面
125 | self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
126 | self.cameraNode.camera.usesOrthographicProjection = YES;
127 | }
128 | break;
129 | case SCN3DDisplayMode_VR360: {
130 |
131 | SCNSphere *sphere = [SCNSphere sphereWithRadius:1.0];
132 | sphere.segmentCount = 96;
133 | self.shapeNode = [SCNNode nodeWithGeometry:sphere];
134 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeClamp;
135 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeClamp;
136 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullFront;
137 | self.shapeNode.geometry.firstMaterial.doubleSided = false; // 设置只渲染一个表面
138 | self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
139 | self.cameraNode.camera.usesOrthographicProjection = NO;
140 |
141 | // SCNMatrix4 contentsTransform = self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform;
142 | //// SCNMatrix4 contentsTransform2 = self.shapeNode.transform;
143 | //
144 | // contentsTransform =SCNMatrix4Rotate(contentsTransform, 0, M_PI, 0, 0);
145 | // self.shapeNode.transform = self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform;
146 |
147 |
148 |
149 | }
150 | break;
151 | case SCN3DDisplayMode_VRGlass: {
152 | SCNSphere *sphere = [SCNSphere sphereWithRadius:1.0];
153 | sphere.segmentCount = 96;
154 | self.shapeNode = [SCNNode nodeWithGeometry:sphere];
155 | self.shapeNode.geometry.firstMaterial.diffuse.wrapT = SCNWrapModeClamp;
156 | self.shapeNode.geometry.firstMaterial.diffuse.wrapS = SCNWrapModeClamp;
157 | self.shapeNode.geometry.firstMaterial.cullMode = SCNCullFront;// 设置剔除外表面
158 | self.shapeNode.geometry.firstMaterial.doubleSided = false; // 设置只渲染一个表面
159 | // self.cameraNode.position = SCNVector3Make(0, 0, 1.5);
160 | self.cameraNode.camera.usesOrthographicProjection = NO;
161 |
162 | self.scViewLeft.frame = CGRectMake(0, 0, self.frame.size.width / 2, self.frame.size.height);
163 | self.scViewRight = [[SCNView alloc] initWithFrame:CGRectMake(self.frame.size.width / 2, 0, self.frame.size.width / 2, self.frame.size.height) options:nil];
164 | self.scViewRight.backgroundColor = [UIColor blackColor];
165 | self.scViewRight.scene = self.scene;
166 | self.scViewRight.antialiasingMode = SCNAntialiasingModeMultisampling4X;
167 | [self addSubview:self.scViewRight];
168 | }
169 | break;
170 |
171 | default:
172 | break;
173 | }
174 |
175 | self.cameraNode.camera.zNear = 0.01f;
176 | self.cameraNode.camera.zFar = 100.0f;
177 | self.shapeNode.castsShadow = NO;
178 | self.shapeNode.position = SCNVector3Make(0, 0, 0);
179 | [self.scene.rootNode addChildNode:self.shapeNode];
180 |
181 | self.modelMatrix = self.shapeNode.transform;
182 | [self setCurrentScale:1.0];
183 | [self setFramesPerVideoImage:nil];
184 | }
185 |
186 | - (void)initParameterSetting {
187 | self.rotateX = 0.0;
188 | self.rotateY = 0.0;
189 | self.minRotateX = - M_PI / 2;
190 | self.maxRotateX = + M_PI / 2;
191 | self.minScale = 1.0;
192 | self.maxScale = 2.0;
193 | self.curScale = 1.0;
194 | self.prevScale = self.curScale;
195 | self.videoAspectRatio = 2.0 / 1.0;
196 | self.scViewLeft.frame = CGRectMake(0, 0, self.frame.size.width, self.frame.size.height);
197 | self.scViewRight = nil;
198 |
199 | self.horizontalEnabled = NO;
200 | self.verticalEnabled = NO;
201 | self.GSensorEnabled = NO;
202 | self.pinchEnabled = NO;
203 | [self stopGSENSORMotion];
204 | }
205 |
206 | - (void)dealloc {
207 |
208 | [self.shapeNode removeFromParentNode];
209 | [self.cameraNode removeFromParentNode];
210 | self.scViewLeft = nil;
211 | self.scViewRight = nil;
212 | [self stopGSENSORMotion];
213 | NSLog(@"=============sceneKit dealloc=======");
214 | }
215 |
216 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
217 | #pragma mark SCN3DPlayerSetting
218 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
219 |
220 | - (void)setInteractiveMode:(SCN3DInteractive_)interactive {
221 | self.interactive = interactive;
222 | }
223 |
224 | - (void)setVideoDisplayMode:(SCN3DDisplayMode_)displayMode {
225 | self.displayMode = displayMode;
226 | [self initSceneNodeWithMode:displayMode];
227 | }
228 |
229 | - (void)setHorizontalEnabled:(BOOL)horEnabled verticalEnabled:(BOOL)verEnabled {
230 | self.horizontalEnabled = horEnabled;
231 | self.verticalEnabled = verEnabled;
232 | }
233 |
234 | - (void)setGSensorMotionEnabled:(BOOL)GSensorEnabled {
235 | self.GSensorEnabled = GSensorEnabled;
236 | if (GSensorEnabled) {
237 | [self startGSENSORMotion];
238 | }
239 | else {
240 | [self stopGSENSORMotion];
241 | }
242 | }
243 |
244 | - (void)setPinchScaleEnabled:(BOOL)pinchEnabled {
245 | self.pinchEnabled = pinchEnabled;
246 | }
247 |
248 | - (void)setVideoAspectRatio:(float)aspectRatio {
249 | self.videoAspRatio = aspectRatio;
250 | }
251 |
252 | - (void)setCurrentOrientation:(UIInterfaceOrientation)orientation {
253 | self.orientation = orientation;
254 | switch (self.displayMode) {
255 | case SCN3DDisplayMode_Plane_Normal:
256 | case SCN3DDisplayMode_Plane_Slide: {
257 | SCNPlane *plane = (SCNPlane *)self.shapeNode.geometry;
258 | float perPixel, videoWidth, videoHeight;
259 |
260 | // 根据当前视图大小和视频宽高比来适配视频显示的宽高
261 | if (orientation == UIDeviceOrientationPortrait) {
262 | perPixel = 2.0 / self.scViewLeft.frame.size.width;
263 | videoWidth = self.scViewLeft.frame.size.width;
264 | videoHeight = videoWidth / self.videoAspRatio;
265 |
266 | if (videoHeight > self.scViewLeft.frame.size.height) {
267 | videoHeight = self.scViewLeft.frame.size.height;
268 | videoWidth = videoHeight * self.videoAspRatio;
269 | }
270 | plane.width = videoWidth * perPixel;
271 | plane.height = videoHeight * perPixel;
272 | }
273 | else {
274 | perPixel = 2.0 / self.scViewLeft.frame.size.height;
275 | videoHeight = self.scViewLeft.frame.size.height;
276 | videoWidth = videoHeight * self.videoAspRatio;
277 |
278 | if (videoWidth > self.scViewLeft.frame.size.width) {
279 | videoWidth = self.scViewLeft.frame.size.width;
280 | videoHeight = videoWidth / self.videoAspRatio;
281 | }
282 | plane.width = videoWidth * perPixel;
283 | plane.height = videoHeight * perPixel;
284 | }
285 | }
286 | break;
287 | case SCN3DDisplayMode_Tube: {
288 | }
289 | break;
290 | case SCN3DDisplayMode_Sphere: {
291 | }
292 | break;
293 | case SCN3DDisplayMode_VR360: {
294 | }
295 | break;
296 | case SCN3DDisplayMode_VRGlass: {
297 | }
298 | break;
299 |
300 | default:
301 | break;
302 | }
303 | }
304 |
305 | - (void)setCurrentScale:(float)curScale {
306 | self.curScale = curScale;
307 | self.shapeNode.scale = SCNVector3Make(curScale, curScale, curScale);
308 | }
309 |
310 | - (void)setMinScale:(float)minScale maxScale:(float)maxScale {
311 | self.minScale = minScale;
312 | self.maxScale = maxScale;
313 | }
314 |
315 | - (void)setCurrentRotateX:(float)rotateX rotateY:(float)rotateY {
316 | [self changeNodeTransformWithRotateX:GLKMathDegreesToRadians(-rotateX) rotateY:GLKMathDegreesToRadians(-rotateY)];
317 | }
318 |
319 | - (void)setVerticalMinRotate:(float)minRotate maxRotate:(float)maxRotate {
320 | if (minRotate < -90) {
321 | minRotate = -90;
322 | }
323 | if (maxRotate > 90) {
324 | maxRotate = 90;
325 | }
326 | self.minRotateX = GLKMathDegreesToRadians(minRotate);
327 | self.maxRotateX = GLKMathDegreesToRadians(maxRotate);
328 | }
329 |
330 | - (void)setTextureOffsetX:(float)x offsetY:(float)y {
331 | SCNMatrix4 contentsTransform = self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform;
332 | contentsTransform = SCNMatrix4Translate(contentsTransform, x, 0, 0);
333 | contentsTransform = SCNMatrix4Translate(contentsTransform, 0, y, 0);
334 | self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform = contentsTransform;
335 | }
336 |
337 | - (void)setTextureScaleX:(float)x ScaleY:(float)y {
338 | SCNMatrix4 contentsTransform = self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform;
339 | contentsTransform = SCNMatrix4Scale(contentsTransform, x, 1.0, 1.0);
340 | contentsTransform = SCNMatrix4Scale(contentsTransform, 1.0, y, 1.0);
341 | self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform = contentsTransform;
342 | }
343 |
344 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
345 | #pragma mark SCN3DPlayer Video Image
346 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
347 |
348 | - (void)setFramesPerVideoImage:(UIImage *)image {
349 | if (image == nil || image.size.width == 0 || image.size.height == 0) {
350 | self.shapeNode.geometry.firstMaterial.diffuse.contents = self.backgroundColor;
351 | }
352 | else {
353 | self.shapeNode.geometry.firstMaterial.diffuse.contents = image;
354 | }
355 | }
356 |
357 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
358 | #pragma mark UITouchEvent And PinchScale
359 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
360 |
361 | - (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
362 | UITouch *touch = [touches anyObject];
363 | CGPoint currLoc = [touch locationInView:self];
364 | CGPoint lastLoc = [touch previousLocationInView:self];
365 | CGPoint moveDiff = CGPointMake(currLoc.x - lastLoc.x, currLoc.y - lastLoc.y);
366 |
367 | float rotX = -1 * GLKMathDegreesToRadians(moveDiff.y / 5.0);
368 | float rotY = -1 * GLKMathDegreesToRadians(moveDiff.x / 5.0);
369 |
370 | rotX = self.verticalEnabled ? rotX : 0;
371 | rotY = self.horizontalEnabled ? rotY : 0;
372 | [self changeNodeTransformWithRotateX:rotX / self.curScale rotateY:rotY / self.curScale];
373 | }
374 |
375 | - (void)changeNodeTransformWithRotateX:(float)rotX rotateY:(float)rotY {
376 | switch (self.displayMode) {
377 | case SCN3DDisplayMode_Plane_Normal: {}
378 | break;
379 | case SCN3DDisplayMode_Plane_Slide: {
380 | SCNMatrix4 contentsTransform = self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform;
381 | contentsTransform = SCNMatrix4Translate(contentsTransform, rotY, 0, 0);
382 | contentsTransform = SCNMatrix4Translate(contentsTransform, 0, rotX, 0);
383 | self.shapeNode.geometry.firstMaterial.diffuse.contentsTransform = contentsTransform;
384 | }
385 | break;
386 | case SCN3DDisplayMode_Tube: {
387 | self.rotateX += rotX;
388 | self.rotateY += rotY;
389 | float minRotate = self.minRotateX / self.curScale;
390 | float maxRotate = self.maxRotateX / self.curScale;
391 |
392 | minRotate = minRotate < (- M_PI / 2) ? (- M_PI / 2) : minRotate;
393 | maxRotate = maxRotate > (+ M_PI / 2) ? (+ M_PI / 2) : maxRotate;
394 | self.rotateX = self.rotateX < minRotate ? minRotate : self.rotateX;
395 | self.rotateX = self.rotateX > maxRotate ? maxRotate : self.rotateX;
396 |
397 | SCNMatrix4 modelViewMatrix = SCNMatrix4Identity;
398 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateY, 0, 1, 0);
399 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateX, 1, 0, 0);
400 | modelViewMatrix = SCNMatrix4Scale(modelViewMatrix, self.curScale, self.curScale, self.curScale);
401 | self.shapeNode.transform = modelViewMatrix;
402 | }
403 | break;
404 | case SCN3DDisplayMode_Sphere: {
405 | self.rotateX += rotX;
406 | self.rotateY += rotY;
407 | float minRotate = self.minRotateX / self.curScale;
408 | float maxRotate = self.maxRotateX / self.curScale;
409 |
410 | minRotate = minRotate < (- M_PI / 2) ? (- M_PI / 2) : minRotate;
411 | maxRotate = maxRotate > (+ M_PI / 2) ? (+ M_PI / 2) : maxRotate;
412 | self.rotateX = self.rotateX < minRotate ? minRotate : self.rotateX;
413 | self.rotateX = self.rotateX > maxRotate ? maxRotate : self.rotateX;
414 |
415 | SCNMatrix4 modelViewMatrix = SCNMatrix4Identity;
416 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateY, 0, 1, 0);
417 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateX, 1, 0, 0);
418 | modelViewMatrix = SCNMatrix4Scale(modelViewMatrix, self.curScale, self.curScale, self.curScale);
419 | self.shapeNode.transform = modelViewMatrix;
420 | }
421 | break;
422 |
423 | default: {
424 | self.rotateX += -rotX;
425 | self.rotateY += -rotY;
426 | float minRotate = self.minRotateX / self.curScale;
427 | float maxRotate = self.maxRotateX / self.curScale;
428 |
429 | minRotate = minRotate < (- M_PI / 2) ? (- M_PI / 2) : minRotate;
430 | maxRotate = maxRotate > (+ M_PI / 2) ? (+ M_PI / 2) : maxRotate;
431 | self.rotateX = self.rotateX < minRotate ? minRotate : self.rotateX;
432 | self.rotateX = self.rotateX > maxRotate ? maxRotate : self.rotateX;
433 | // NSLog(@"self.rotateX = %f, %f", self.rotateX, GLKMathRadiansToDegrees(self.rotateX));
434 |
435 | SCNMatrix4 modelViewMatrix = SCNMatrix4Identity;
436 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateY, 0, 1, 0);
437 | modelViewMatrix = SCNMatrix4Rotate(modelViewMatrix, -self.rotateX, 1, 0, 0);
438 | modelViewMatrix = SCNMatrix4Scale(modelViewMatrix, self.curScale, self.curScale, self.curScale);
439 | self.shapeNode.transform = modelViewMatrix;
440 | }
441 | break;
442 | }
443 | }
444 |
445 | - (void)handlePinchScale:(UIPinchGestureRecognizer *)paramSender {
446 | if (!self.pinchEnabled) return;
447 | if (paramSender.state != UIGestureRecognizerStateEnded && paramSender.state != UIGestureRecognizerStateFailed) {
448 | if (paramSender.scale != NAN && paramSender.scale != 0.0) {
449 |
450 | float scale = (paramSender.scale - 1) * 0.50;
451 | self.curScale = scale + self.prevScale;
452 |
453 | if (self.curScale < self.minScale) {
454 | self.curScale = self.minScale;
455 | }
456 | else if (self.curScale > self.maxScale) {
457 | self.curScale = self.maxScale;
458 | }
459 |
460 | [self setCurrentScale:self.curScale];
461 | }
462 | } else if(paramSender.state == UIGestureRecognizerStateEnded) {
463 | self.prevScale = self.curScale;
464 | }
465 | }
466 |
467 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
468 | #pragma mark G-SENSOR Motion
469 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
470 |
471 | - (void)startGSENSORMotion {
472 | float gFPS = 30.0f;
473 | if (self.displayMode == SCN3DDisplayMode_VRGlass) {
474 | gFPS = 120.0f;
475 | }
476 | self.motionManager = [[CMMotionManager alloc] init];
477 | self.motionManager.deviceMotionUpdateInterval = 1.0f / gFPS;
478 | self.motionManager.gyroUpdateInterval = 1.0f / gFPS;
479 | self.motionManager.showsDeviceMovementDisplay = YES;
480 | self.rotateX = 0.0f;
481 | self.rotateY = 0.0f;
482 |
483 | NSOperationQueue* motionQueue = [[NSOperationQueue alloc] init];
484 | [self.motionManager startDeviceMotionUpdatesToQueue:motionQueue withHandler:^(CMDeviceMotion * _Nullable motion, NSError * _Nullable error) {
485 | float damping = 30.0;
486 | double rotateX = -motion.rotationRate.y / damping; // X 轴旋转
487 | double rotateY = -motion.rotationRate.x / damping; // Y 轴旋转
488 |
489 | switch (self.orientation) {
490 | case UIDeviceOrientationLandscapeRight:
491 | rotateX = +motion.rotationRate.x / damping;
492 | rotateY = -motion.rotationRate.y / damping;
493 | break;
494 | case UIDeviceOrientationLandscapeLeft:
495 | rotateX = -motion.rotationRate.x / damping;
496 | rotateY = +motion.rotationRate.y / damping;
497 | break;
498 | case UIDeviceOrientationPortrait:
499 | default:
500 | break;
501 | }
502 | [self changeNodeTransformWithRotateX:(rotateY / 2) / self.curScale rotateY:rotateX / self.curScale];
503 | }];
504 | }
505 |
506 | - (void)stopGSENSORMotion {
507 | [self.motionManager stopDeviceMotionUpdates];
508 | self.motionManager = nil;
509 | }
510 |
511 | @end
512 |
--------------------------------------------------------------------------------
/SCN3DPlayer/SCN3DPlayer/SCN3DVideoAdatper.h:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DVideoAdatper.h
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import
10 | #import
11 |
12 |
13 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
14 |
15 | @class SCN3DVideoAdatper;
16 |
17 | @protocol SCN3DVideoAdatperDelegate
18 |
19 | @optional
20 |
21 | /**
22 | 准备播放视频
23 | 实现SCN3DVideoAdatperDelegate协议最先调用该方法
24 |
25 | @param videoAdatper SCN3DVideoAdatper对象
26 |
27 | */
28 | - (void)videoPlayerIsReadyToPlayVideo:(SCN3DVideoAdatper *)videoAdatper;
29 |
30 | /**
31 | 播放视频结束
32 | 实现SCN3DVideoAdatperDelegate协议 在视频播放结束以后调用该方法
33 |
34 | @param videoAdatper SCN3DVideoAdatper
35 | */
36 | - (void)videoPlayerDidReachEnd:(SCN3DVideoAdatper *)videoAdatper;
37 |
38 | /**
39 | 播放时间监听
40 | 实现SCN3DVideoAdatperDelegate协议 在视频播放时会返回当前播放的时间
41 |
42 | @param videoAdatper SCN3DVideoAdatper 对象
43 | @param cmTime CMTime
44 | */
45 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper timeDidChange:(CMTime)cmTime;
46 |
47 | /**
48 | 播放已加载的缓存时间监听
49 | 实现SCN3DVideoAdatperDelegate协议 在视频播放的时候会返回当前已加载的视频缓存百分比
50 | @param videoAdatper SCN3DVideoAdatper 对象
51 | @param duration float
52 | */
53 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper loadedTimeRangeDidChange:(float)duration;
54 |
55 | /**
56 | 播放错误监听
57 | 实现SCN3DVideoAdatperDelegate协议 在播放视频失败的时候会调用该方法
58 |
59 | @param videoAdatper SCN3DVideoAdatper 对象
60 | @param error NSError 对象
61 | */
62 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper didFailWithError:(NSError *)error;
63 |
64 | /**
65 | 获取视频的每一帧
66 | 实现SCN3DVideoAdatperDelegate协议 在视频播放的时候,该方法可以得到视频得每一帧图片
67 |
68 | @param videoAdatper SCN3DVideoAdatper 对象
69 | @param videoImage UIImage 对象
70 | */
71 | - (void)videoPlayer:(SCN3DVideoAdatper *)videoAdatper displaylinkCallbackImage:(UIImage *)videoImage;
72 |
73 | @end
74 |
75 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
76 |
77 | @interface SCN3DVideoAdatper : NSObject
78 |
79 | @property (nonatomic, weak) id delegate;
80 | @property (nonatomic, strong, readonly) AVPlayer *player;
81 | @property (nonatomic, strong, readonly) AVPlayerItem *playerItem;
82 | @property (nonatomic, strong, readonly) AVPlayerItemVideoOutput *output;
83 | @property (nonatomic, assign, getter=isPlaying, readonly) BOOL playing;
84 | @property (nonatomic, assign, getter=isLooping) BOOL looping;
85 | @property (nonatomic, assign, getter=isMuted) BOOL muted;
86 |
87 | // Setting
88 |
89 | - (void)setURL:(NSURL *)URL;
90 | - (void)setPlayerItem:(AVPlayerItem *)playerItem;
91 | - (void)setAsset:(AVAsset *)asset;
92 |
93 |
94 | // 开始播放
95 | - (void)play;
96 | //暂停播放
97 | - (void)pause;
98 | //重置播放器
99 | - (void)reset;
100 |
101 | /**
102 | 跳转到相应的时间段
103 | 在相应的时间段里面播放
104 |
105 | @param time 传入一个float 得参数,
106 | @param completion completion description
107 | */
108 | - (void)seekToTime:(float)time completion:(void (^)())completion;
109 |
110 | //设置音量大小
111 | - (void)setVolume:(float)volume;
112 | //增加音量
113 | - (void)fadeInVolume;
114 | //降低音量
115 | - (void)fadeOutVolume;
116 |
117 | // 添加 Displaylink
118 | - (void)addDisplaylink;
119 | // 移除 Displaylink
120 | - (void)removeDisplaylink;
121 |
122 | @end
123 |
--------------------------------------------------------------------------------
/SCN3DPlayer/SCN3DPlayer/SCN3DVideoAdatper.m:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DVideoAdatper.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import "SCN3DVideoAdatper.h"
10 | #import
11 |
12 | static const float DefaultVolumeFadeDuration = 1.0f;
13 | static const float TimeObserverInterval = 0.01f;
14 |
15 | static NSString * const kVideoPlayerErrorDomain = @"kVideoPlayerErrorDomain";
16 | static void *VideoPlayer_PlayerItemStatusContext = &VideoPlayer_PlayerItemStatusContext;
17 | static void *VideoPlayer_PlayerRateChangedContext = &VideoPlayer_PlayerRateChangedContext;
18 | static void *VideoPlayer_PlayerItemLoadedTimeRangesContext = &VideoPlayer_PlayerItemLoadedTimeRangesContext;
19 |
20 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
21 |
22 | @interface SCN3DVideoAdatper ()
23 |
24 | @property (nonatomic, strong, readwrite) AVPlayer *player;
25 | @property (nonatomic, strong, readwrite) AVPlayerItem *playerItem;
26 | @property (nonatomic, strong, readwrite) AVPlayerItemVideoOutput *output;
27 |
28 | @property (nonatomic, assign, getter=isPlaying, readwrite) BOOL playing;
29 | @property (nonatomic, assign, getter=isSeeking) BOOL seeking;
30 | @property (nonatomic, assign) BOOL isAtEndTime;
31 | @property (nonatomic, strong) id timeObserverToken;
32 | @property (nonatomic, strong) CADisplayLink *displayLink; // 同步显示器的刷新频率
33 |
34 | @end
35 |
36 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
37 |
38 | @implementation SCN3DVideoAdatper
39 |
40 | - (void)dealloc {
41 | [self resetPlayerItemIfNecessary];
42 | [self removePlayerObservers];
43 | [self removeTimeObserver];
44 | [self cancelFadeVolume];
45 | NSLog(@"===============player dealloc===========");
46 | }
47 |
48 | - (id)init {
49 | if (self = [super init]) {
50 | [self setupPlayer];
51 | [self addPlayerObservers];
52 | [self setupAudioSession];
53 | NSDictionary *pixBuffAttributes = @{(id)kCVPixelBufferPixelFormatTypeKey: @(kCVPixelFormatType_32BGRA)};
54 | self.output = [[AVPlayerItemVideoOutput alloc] initWithPixelBufferAttributes:pixBuffAttributes];
55 | }
56 | return self;
57 | }
58 |
59 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
60 | #pragma mark - Setup
61 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
62 |
63 | - (void)setupPlayer {
64 | self.player = [[AVPlayer alloc] init];
65 | self.muted = NO;
66 | self.looping = NO;
67 | [self setVolume:1.0f];
68 | [self addTimeObserver];
69 | }
70 |
71 | - (void)setupAudioSession {
72 | NSError *categoryError = nil;
73 | BOOL success = [[AVAudioSession sharedInstance] setCategory:AVAudioSessionCategoryPlayback error:&categoryError];
74 | if (!success) {
75 | NSLog(@"Error setting audio session category: %@", categoryError);
76 | }
77 |
78 | NSError *activeError = nil;
79 | success = [[AVAudioSession sharedInstance] setActive:YES error:&activeError];
80 | if (!success) {
81 | NSLog(@"Error setting audio session active: %@", activeError);
82 | }
83 | }
84 |
85 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
86 | #pragma mark - Public API
87 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
88 |
89 | - (void)setURL:(NSURL *)URL {
90 | if (URL == nil) {
91 | return;
92 | }
93 | [self resetPlayerItemIfNecessary];
94 |
95 | AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithURL:URL];
96 | if (!playerItem) {
97 | [self reportUnableToCreatePlayerItem];
98 | return;
99 | }
100 | [self preparePlayerItem:playerItem];
101 | }
102 |
103 | - (void)setPlayerItem:(AVPlayerItem *)playerItem {
104 | if (playerItem == nil) {
105 | return;
106 | }
107 | [self resetPlayerItemIfNecessary];
108 | [self preparePlayerItem:playerItem];
109 | }
110 |
111 | - (void)setAsset:(AVAsset *)asset {
112 | if (asset == nil) {
113 | return;
114 | }
115 | [self resetPlayerItemIfNecessary];
116 |
117 | AVPlayerItem *playerItem = [[AVPlayerItem alloc] initWithAsset:asset automaticallyLoadedAssetKeys:@[NSStringFromSelector(@selector(tracks))]];
118 | if (!playerItem) {
119 | [self reportUnableToCreatePlayerItem];
120 | return;
121 | }
122 | [self preparePlayerItem:playerItem];
123 | }
124 |
125 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
126 | #pragma mark - Accessor Overrides
127 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
128 |
129 | - (void)setMuted:(BOOL)muted {
130 | if (self.player) {
131 | self.player.muted = muted;
132 | }
133 | }
134 |
135 | - (BOOL)isMuted {
136 | return self.player.isMuted;
137 | }
138 |
139 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
140 | #pragma mark - Playback
141 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
142 |
143 | - (void)play {
144 | if (self.player.currentItem == nil) {
145 | return;
146 | }
147 | self.playing = YES;
148 |
149 | if ([self.player.currentItem status] == AVPlayerItemStatusReadyToPlay) {
150 | if ([self isAtEndTime]) {
151 | [self restart];
152 | }
153 | else {
154 | [self.player play];
155 | }
156 | }
157 | }
158 |
159 | - (void)pause {
160 | self.playing = NO;
161 | [self.player pause];
162 | }
163 |
164 | - (void)reset {
165 | [self pause];
166 | [self resetPlayerItemIfNecessary];
167 | }
168 |
169 | - (void)seekToTime:(float)time completion:(void (^)())completion {
170 | if (_seeking) {
171 | return;
172 | }
173 |
174 | if (self.player) {
175 | CMTime cmTime = CMTimeMakeWithSeconds(time, self.player.currentTime.timescale);
176 | if (CMTIME_IS_INVALID(cmTime) || self.player.currentItem.status != AVPlayerStatusReadyToPlay) {
177 | return;
178 | }
179 |
180 | _seeking = YES;
181 | __weak typeof(self) weakSelf = self;
182 | dispatch_async(dispatch_get_global_queue(DISPATCH_QUEUE_PRIORITY_DEFAULT, 0), ^{
183 | [self.player seekToTime:cmTime completionHandler:^(BOOL finished) {
184 | weakSelf.isAtEndTime = NO;
185 | weakSelf.seeking = NO;
186 | if (completion) {
187 | dispatch_async( dispatch_get_main_queue(), ^{
188 | completion();
189 | });
190 | }
191 | }];
192 | });
193 | }
194 | }
195 |
196 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
197 | #pragma mark - Volume
198 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
199 |
200 | - (void)setVolume:(float)volume {
201 | [self cancelFadeVolume];
202 | self.player.volume = volume;
203 | }
204 |
205 | - (void)cancelFadeVolume {
206 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fadeInVolume) object:nil];
207 | [NSObject cancelPreviousPerformRequestsWithTarget:self selector:@selector(fadeOutVolume) object:nil];
208 | }
209 |
210 | - (void)fadeInVolume {
211 | if (self.player == nil) {
212 | return;
213 | }
214 | [self cancelFadeVolume];
215 |
216 | if (self.player.volume >= 1.0f - 0.01f) {
217 | self.player.volume = 1.0f;
218 | }
219 | else {
220 | self.player.volume += 1.0f/10.0f;
221 | [self performSelector:@selector(fadeInVolume) withObject:nil afterDelay:DefaultVolumeFadeDuration/10.0f];
222 | }
223 | }
224 |
225 | - (void)fadeOutVolume {
226 | if (self.player == nil) {
227 | return;
228 | }
229 | [self cancelFadeVolume];
230 |
231 | if (self.player.volume <= 0.01f) {
232 | self.player.volume = 0.0f;
233 | }
234 | else {
235 | self.player.volume -= 1.0f/10.0f;
236 | [self performSelector:@selector(fadeOutVolume) withObject:nil afterDelay:DefaultVolumeFadeDuration/10.0f];
237 | }
238 | }
239 |
240 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
241 | #pragma mark - Displaylink
242 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
243 |
244 | - (void)addDisplaylink {
245 | self.displayLink = [CADisplayLink displayLinkWithTarget:self selector:@selector(displayLinkCallback:)];
246 | [self.displayLink addToRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
247 | }
248 |
249 | - (void)removeDisplaylink {
250 | if (self.displayLink) {
251 | [self.displayLink removeFromRunLoop:[NSRunLoop mainRunLoop] forMode:NSRunLoopCommonModes];
252 | self.displayLink = nil;
253 | }
254 | }
255 |
256 | - (void)displayLinkCallback:(CADisplayLink *)sender {
257 | @autoreleasepool {
258 | CMTime outputItemTime = [self.output itemTimeForHostTime:CACurrentMediaTime()];
259 | if([self.output hasNewPixelBufferForItemTime:outputItemTime]) {
260 | CVPixelBufferRef bufferRef = [self.output copyPixelBufferForItemTime:outputItemTime itemTimeForDisplay:NULL];
261 |
262 | if (bufferRef != nil) {
263 | UIImage *videoImage = [self pixelBufferToImage:bufferRef];
264 | if ([self.delegate respondsToSelector:@selector(videoPlayer:displaylinkCallbackImage:)]) {
265 | [self.delegate videoPlayer:self displaylinkCallbackImage:videoImage];
266 | }
267 | CFRelease(bufferRef);
268 | }
269 | }
270 | }
271 |
272 | }
273 |
274 | - (UIImage *)pixelBufferToImage:(CVPixelBufferRef)bufferRef {
275 | CIImage *ciImage = [CIImage imageWithCVPixelBuffer:bufferRef];
276 | CIContext *tempContext = [CIContext contextWithOptions:nil];
277 | CGFloat videoWidth = CVPixelBufferGetWidth(bufferRef);
278 | CGFloat videoHeight = CVPixelBufferGetHeight(bufferRef);
279 | CGImageRef videoImage = [tempContext createCGImage:ciImage fromRect:CGRectMake(0, 0, videoWidth, videoHeight)];
280 |
281 | UIImage *image = [UIImage imageWithCGImage:videoImage];
282 | CGImageRelease(videoImage);
283 | return image;
284 | }
285 |
286 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
287 | #pragma mark - Private API
288 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
289 |
290 | - (void)reportUnableToCreatePlayerItem {
291 | if ([self.delegate respondsToSelector:@selector(videoPlayer:didFailWithError:)]) {
292 | NSError *error = [NSError errorWithDomain:kVideoPlayerErrorDomain
293 | code:0
294 | userInfo:@{NSLocalizedDescriptionKey : @"Unable to create AVPlayerItem."}];
295 |
296 | [self.delegate videoPlayer:self didFailWithError:error];
297 | }
298 | }
299 |
300 | - (void)resetPlayerItemIfNecessary {
301 | if (self.playerItem) {
302 | [self removePlayerItemObservers:self.playerItem];
303 | [self.player replaceCurrentItemWithPlayerItem:nil];
304 | [self.playerItem removeOutput:self.output];
305 | self.playerItem = nil;
306 | }
307 | _playing = NO;
308 | _isAtEndTime = NO;
309 | }
310 |
311 | - (void)preparePlayerItem:(AVPlayerItem *)playerItem {
312 | NSParameterAssert(playerItem);
313 | _playerItem = playerItem;
314 | [self addPlayerItemObservers:playerItem];
315 | [self.player replaceCurrentItemWithPlayerItem:playerItem];
316 | }
317 |
318 | - (void)restart {
319 | __weak typeof(self) weakSelf = self;
320 | [self.player seekToTime:kCMTimeZero toleranceBefore:kCMTimeZero toleranceAfter:kCMTimeZero completionHandler:^(BOOL finished) {
321 | weakSelf.isAtEndTime = NO;
322 | if (weakSelf.isPlaying) {
323 | [weakSelf play];
324 | }
325 | }];
326 | }
327 |
328 | - (BOOL)isAtEndTime { // TODO: this is a fucked up override, seems like something could be wrong [AH]
329 | if (self.player && self.player.currentItem) {
330 | if (_isAtEndTime) {
331 | return _isAtEndTime;
332 | }
333 |
334 | float currentTime = 0.0f;
335 | if (CMTIME_IS_INVALID(self.player.currentTime) == NO) {
336 | currentTime = CMTimeGetSeconds(self.player.currentTime);
337 | }
338 |
339 | float videoDuration = 0.0f;
340 | if (CMTIME_IS_INVALID(self.player.currentItem.duration) == NO) {
341 | videoDuration = CMTimeGetSeconds(self.player.currentItem.duration);
342 | }
343 |
344 | if (currentTime > 0.0f && videoDuration > 0.0f) {
345 | if (fabs(currentTime - videoDuration) <= 0.01f) {
346 | return YES;
347 | }
348 | }
349 | }
350 | return NO;
351 | }
352 |
353 | - (float)calcLoadedDuration {
354 | float loadedDuration = 0.0f;
355 | if (self.player && self.player.currentItem) {
356 | NSArray *loadedTimeRanges = self.player.currentItem.loadedTimeRanges;
357 |
358 | if (loadedTimeRanges && [loadedTimeRanges count]) {
359 | CMTimeRange timeRange = [[loadedTimeRanges firstObject] CMTimeRangeValue];
360 | float startSeconds = CMTimeGetSeconds(timeRange.start);
361 | float durationSeconds = CMTimeGetSeconds(timeRange.duration);
362 | loadedDuration = startSeconds + durationSeconds;
363 | }
364 | }
365 | return loadedDuration;
366 | }
367 |
368 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
369 | #pragma mark - Player Observers
370 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
371 |
372 | - (void)addPlayerObservers {
373 | [self.player addObserver:self
374 | forKeyPath:NSStringFromSelector(@selector(rate))
375 | options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
376 | context:VideoPlayer_PlayerRateChangedContext];
377 | }
378 |
379 | - (void)removePlayerObservers {
380 | @try {
381 | [self.player removeObserver:self
382 | forKeyPath:NSStringFromSelector(@selector(rate))
383 | context:VideoPlayer_PlayerRateChangedContext];
384 | }
385 | @catch (NSException *exception) {
386 | NSLog(@"Exception removing observer: %@", exception);
387 | }
388 | }
389 |
390 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
391 | #pragma mark - PlayerItem Observers
392 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
393 |
394 | - (void)addPlayerItemObservers:(AVPlayerItem *)playerItem {
395 | [playerItem addObserver:self
396 | forKeyPath:NSStringFromSelector(@selector(status))
397 | options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionOld | NSKeyValueObservingOptionNew
398 | context:VideoPlayer_PlayerItemStatusContext];
399 |
400 | [playerItem addObserver:self
401 | forKeyPath:NSStringFromSelector(@selector(loadedTimeRanges))
402 | options:NSKeyValueObservingOptionInitial | NSKeyValueObservingOptionNew
403 | context:VideoPlayer_PlayerItemLoadedTimeRangesContext];
404 |
405 | [[NSNotificationCenter defaultCenter] addObserver:self
406 | selector:@selector(playerItemDidPlayToEndTime:)
407 | name:AVPlayerItemDidPlayToEndTimeNotification
408 | object:playerItem];
409 | }
410 |
411 | - (void)removePlayerItemObservers:(AVPlayerItem *)playerItem {
412 | [playerItem cancelPendingSeeks];
413 | @try {
414 | [playerItem removeObserver:self
415 | forKeyPath:NSStringFromSelector(@selector(status))
416 | context:VideoPlayer_PlayerItemStatusContext];
417 | }
418 | @catch (NSException *exception) {
419 | NSLog(@"Exception removing observer: %@", exception);
420 | }
421 |
422 | @try {
423 | [playerItem removeObserver:self
424 | forKeyPath:NSStringFromSelector(@selector(loadedTimeRanges))
425 | context:VideoPlayer_PlayerItemLoadedTimeRangesContext];
426 | }
427 | @catch (NSException *exception) {
428 | NSLog(@"Exception removing observer: %@", exception);
429 | }
430 | [[NSNotificationCenter defaultCenter] removeObserver:self name:AVPlayerItemDidPlayToEndTimeNotification object:playerItem];
431 | }
432 |
433 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
434 | #pragma mark - Time Observer
435 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
436 |
437 | - (void)addTimeObserver {
438 | if (self.timeObserverToken || self.player == nil) {
439 | return;
440 | }
441 |
442 | __weak typeof (self) weakSelf = self;
443 | self.timeObserverToken = [self.player addPeriodicTimeObserverForInterval:CMTimeMakeWithSeconds(TimeObserverInterval, NSEC_PER_SEC)
444 | queue:dispatch_get_main_queue()
445 | usingBlock:^(CMTime time)
446 | {
447 | __strong typeof (self) strongSelf = weakSelf;
448 | if (!strongSelf) {
449 | return;
450 | }
451 | if ([strongSelf.delegate respondsToSelector:@selector(videoPlayer:timeDidChange:)]) {
452 | [strongSelf.delegate videoPlayer:strongSelf timeDidChange:time];
453 | }
454 | }];
455 | }
456 |
457 | - (void)removeTimeObserver {
458 | if (self.timeObserverToken == nil) {
459 | return;
460 | }
461 | if (self.player) {
462 | [self.player removeTimeObserver:self.timeObserverToken];
463 | }
464 | self.timeObserverToken = nil;
465 | }
466 |
467 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
468 | #pragma mark - Observer Response
469 | /////////////////////////////////////////////////////////////////////////////////////////////////////////
470 |
471 | - (void)observeValueForKeyPath:(NSString *)keyPath ofObject:(id)object change:(NSDictionary *)change context:(void *)context {
472 | if (context == VideoPlayer_PlayerRateChangedContext) {
473 | // if (self.playerItem != nil) {
474 | // NSLog(@"TODO: Show loading indicator");
475 | // }
476 | }
477 | else if (context == VideoPlayer_PlayerItemStatusContext) {
478 | AVPlayerStatus newStatus = [[change objectForKey:NSKeyValueChangeNewKey] integerValue];
479 | AVPlayerStatus oldStatus = [[change objectForKey:NSKeyValueChangeOldKey] integerValue];
480 |
481 | if (newStatus != oldStatus) {
482 | switch (newStatus) {
483 | case AVPlayerItemStatusUnknown: {
484 | NSLog(@"Video player Status Unknown");
485 | }
486 | break;
487 | case AVPlayerItemStatusReadyToPlay: {
488 | if ([self.delegate respondsToSelector:@selector(videoPlayerIsReadyToPlayVideo:)]) {
489 | dispatch_async(dispatch_get_main_queue(), ^{
490 | [self.playerItem addOutput:self.output];
491 | [self.delegate videoPlayerIsReadyToPlayVideo:self];
492 | });
493 | }
494 | }
495 | break;
496 | case AVPlayerItemStatusFailed: {
497 | NSLog(@"Video player Status Failed: player item error = %@", self.player.currentItem.error);
498 | NSLog(@"Video player Status Failed: player error = %@", self.player.error);
499 |
500 | NSError *error = self.player.error;
501 | if (!error) {
502 | error = self.player.currentItem.error;
503 | }
504 | else {
505 | error = [NSError errorWithDomain:kVideoPlayerErrorDomain
506 | code:0
507 | userInfo:@{NSLocalizedDescriptionKey : @"unknown player error, status == AVPlayerItemStatusFailed"}];
508 | }
509 | [self reset];
510 |
511 | if ([self.delegate respondsToSelector:@selector(videoPlayer:didFailWithError:)]) {
512 | dispatch_async(dispatch_get_main_queue(), ^{
513 | [self.delegate videoPlayer:self didFailWithError:error];
514 | });
515 | }
516 | }
517 | break;
518 | default:
519 | break;
520 | }
521 | }
522 | }
523 | else if (context == VideoPlayer_PlayerItemLoadedTimeRangesContext) {
524 | float loadedDuration = [self calcLoadedDuration];
525 | if ([self.delegate respondsToSelector:@selector(videoPlayer:loadedTimeRangeDidChange:)]) {
526 | [self.delegate videoPlayer:self loadedTimeRangeDidChange:loadedDuration];
527 | }
528 | }
529 | else {
530 | [super observeValueForKeyPath:keyPath ofObject:object change:change context:context];
531 | }
532 | }
533 |
534 | - (void)playerItemDidPlayToEndTime:(NSNotification *)notification {
535 | if (notification.object != self.player.currentItem) {
536 | return;
537 | }
538 |
539 | if (self.isLooping) {
540 | [self restart];
541 | }
542 | else {
543 | _isAtEndTime = YES;
544 | self.playing = NO;
545 | }
546 |
547 | if ([self.delegate respondsToSelector:@selector(videoPlayerDidReachEnd:)]) {
548 | [self.delegate videoPlayerDidReachEnd:self];
549 | }
550 | }
551 |
552 | @end
553 |
--------------------------------------------------------------------------------
/SCN3DPlayer/ViewController.h:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.h
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface ViewController : UIViewController
12 |
13 |
14 | @end
15 |
16 |
--------------------------------------------------------------------------------
/SCN3DPlayer/ViewController.m:
--------------------------------------------------------------------------------
1 | //
2 | // ViewController.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 俞涛涛 on 16/11/11.
6 | // Copyright © 2016年 俞涛涛. All rights reserved.
7 | //
8 |
9 | #import "ViewController.h"
10 |
11 | #import "HelloViewController.h"
12 |
13 | @interface ViewController (){
14 |
15 |
16 | }
17 |
18 |
19 | @end
20 |
21 | @implementation ViewController
22 |
23 | - (void)viewDidLoad {
24 | [super viewDidLoad];
25 | // Do any additional setup after loading the view, typically from a nib.
26 | }
27 | - (IBAction)btnClick:(UIButton *)sender {
28 | // [self performSegueWithIdentifier:@"segue1" sender:self];
29 | HelloViewController * hVC = [[HelloViewController alloc]init];
30 | [self presentViewController:hVC animated:YES completion:nil];
31 |
32 | }
33 | - (void)prepareForSegue:(UIStoryboardSegue *)segue sender:(id)sender {
34 | if ([segue.identifier isEqualToString:@"segue1"]) {
35 | // HelloViewController * helloVc = segue.destinationViewController;
36 |
37 |
38 |
39 |
40 | }
41 | }
42 | - (void)didReceiveMemoryWarning {
43 | [super didReceiveMemoryWarning];
44 | // Dispose of any resources that can be recreated.
45 | }
46 |
47 |
48 | @end
49 |
--------------------------------------------------------------------------------
/SCN3DPlayer/image/aaa.jpg:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer/image/aaa.jpg
--------------------------------------------------------------------------------
/SCN3DPlayer/image/abc.mp4:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer/image/abc.mp4
--------------------------------------------------------------------------------
/SCN3DPlayer/image/ic_circle@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer/image/ic_circle@2x.png
--------------------------------------------------------------------------------
/SCN3DPlayer/image/pause_nor@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer/image/pause_nor@2x.png
--------------------------------------------------------------------------------
/SCN3DPlayer/image/play_nor@2x.png:
--------------------------------------------------------------------------------
https://raw.githubusercontent.com/hhjdk/SCN3DPlayer/8e85d9e652f0c356eaf42c498ece8c910ffb776f/SCN3DPlayer/image/play_nor@2x.png
--------------------------------------------------------------------------------
/SCN3DPlayer/main.m:
--------------------------------------------------------------------------------
1 | //
2 | // main.m
3 | // SCN3DPlayer
4 | //
5 | // Created by 泰吉通 on 16/11/11.
6 | // Copyright © 2016年 泰吉通. All rights reserved.
7 | //
8 |
9 | #import
10 | #import "AppDelegate.h"
11 |
12 | int main(int argc, char * argv[]) {
13 | @autoreleasepool {
14 | return UIApplicationMain(argc, argv, nil, NSStringFromClass([AppDelegate class]));
15 | }
16 | }
17 |
--------------------------------------------------------------------------------
/SCN3DPlayerTests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SCN3DPlayerTests/SCN3DPlayerTests.m:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DPlayerTests.m
3 | // SCN3DPlayerTests
4 | //
5 | // Created by 泰吉通 on 16/11/11.
6 | // Copyright © 2016年 泰吉通. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SCN3DPlayerTests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation SCN3DPlayerTests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 | // Put setup code here. This method is called before the invocation of each test method in the class.
20 | }
21 |
22 | - (void)tearDown {
23 | // Put teardown code here. This method is called after the invocation of each test method in the class.
24 | [super tearDown];
25 | }
26 |
27 | - (void)testExample {
28 | // This is an example of a functional test case.
29 | // Use XCTAssert and related functions to verify your tests produce the correct results.
30 | }
31 |
32 | - (void)testPerformanceExample {
33 | // This is an example of a performance test case.
34 | [self measureBlock:^{
35 | // Put the code you want to measure the time of here.
36 | }];
37 | }
38 |
39 | @end
40 |
--------------------------------------------------------------------------------
/SCN3DPlayerUITests/Info.plist:
--------------------------------------------------------------------------------
1 |
2 |
3 |
4 |
5 | CFBundleDevelopmentRegion
6 | en
7 | CFBundleExecutable
8 | $(EXECUTABLE_NAME)
9 | CFBundleIdentifier
10 | $(PRODUCT_BUNDLE_IDENTIFIER)
11 | CFBundleInfoDictionaryVersion
12 | 6.0
13 | CFBundleName
14 | $(PRODUCT_NAME)
15 | CFBundlePackageType
16 | BNDL
17 | CFBundleShortVersionString
18 | 1.0
19 | CFBundleVersion
20 | 1
21 |
22 |
23 |
--------------------------------------------------------------------------------
/SCN3DPlayerUITests/SCN3DPlayerUITests.m:
--------------------------------------------------------------------------------
1 | //
2 | // SCN3DPlayerUITests.m
3 | // SCN3DPlayerUITests
4 | //
5 | // Created by 泰吉通 on 16/11/11.
6 | // Copyright © 2016年 泰吉通. All rights reserved.
7 | //
8 |
9 | #import
10 |
11 | @interface SCN3DPlayerUITests : XCTestCase
12 |
13 | @end
14 |
15 | @implementation SCN3DPlayerUITests
16 |
17 | - (void)setUp {
18 | [super setUp];
19 |
20 | // Put setup code here. This method is called before the invocation of each test method in the class.
21 |
22 | // In UI tests it is usually best to stop immediately when a failure occurs.
23 | self.continueAfterFailure = NO;
24 | // UI tests must launch the application that they test. Doing this in setup will make sure it happens for each test method.
25 | [[[XCUIApplication alloc] init] launch];
26 |
27 | // In UI tests it’s important to set the initial state - such as interface orientation - required for your tests before they run. The setUp method is a good place to do this.
28 | }
29 |
30 | - (void)tearDown {
31 | // Put teardown code here. This method is called after the invocation of each test method in the class.
32 | [super tearDown];
33 | }
34 |
35 | - (void)testExample {
36 | // Use recording to get started writing UI tests.
37 | // Use XCTAssert and related functions to verify your tests produce the correct results.
38 | }
39 |
40 | @end
41 |
--------------------------------------------------------------------------------