CameraViewController.m
21.5 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
//
// CameraView.m
// Camera
//
// Created by wzh on 2017/6/2.
// Copyright © 2017年 wzh. All rights reserved.
//
#import "CameraViewController.h"
#import <AssetsLibrary/AssetsLibrary.h>
#import "ClipViewController.h"
#import "Masonry.h"
#import "SVProgressHUD.h"
#define KWIDTH [UIScreen mainScreen].bounds.size.width
#define KHEIGHT [UIScreen mainScreen].bounds.size.height
@interface CameraViewController ()<UIGestureRecognizerDelegate,UINavigationControllerDelegate,UIImagePickerControllerDelegate,ClipPhotoDelegate>
/**
* AVCaptureSession对象来执行输入设备和输出设备之间的数据传递
*/
@property (nonatomic, strong) AVCaptureSession* session;
/**
* AVCaptureDevice 照相设备
*/
@property (nonatomic, strong) AVCaptureDevice* device;
/**
* 输入设备
*/
@property (nonatomic, strong) AVCaptureDeviceInput* videoInput;
/**
* 照片输出流
*/
@property (nonatomic, strong) AVCaptureStillImageOutput* stillImageOutput;
/**
* 预览图层
*/
@property (nonatomic, strong) AVCaptureVideoPreviewLayer* previewLayer;
/**
* 记录开始的缩放比例
*/
@property(nonatomic,assign)CGFloat beginGestureScale;
/**
* 最后的缩放比例
*/
@property(nonatomic,assign)CGFloat effectiveScale;
@property (nonatomic, strong) AVCaptureConnection *stillImageConnection;
@property (nonatomic, strong) NSData *jpegData;
@property (nonatomic, assign) CFDictionaryRef attachments;
@property (nonatomic, strong) UIView *toolView;
@property (nonatomic, strong) UIView *editorView;
@property (nonatomic, strong) UIImagePickerController *imgPicker;
@end
@implementation CameraViewController{
BOOL isTakePhoto;
BOOL isPostBack;
}
- (void)viewDidLoad {
[super viewDidLoad];
isPostBack = NO;
[self initAVCaptureSession];
[self setUpGesture];
}
- (void)createdTool
{
[self.mainLayout.layer addSublayer:self.previewLayer];
UIView *headerView = [[UIView alloc] initWithFrame:CGRectMake(0, 30, KWIDTH, TOP_OFFSET)];
headerView.backgroundColor = [UIColor blackColor];
headerView.alpha = 0.8;
[self.mainLayout addSubview:headerView];
UILabel *titleLable = [[UILabel alloc] initWithFrame:CGRectMake((KWIDTH - 100)/2.0, 12, 100, 40)];
titleLable.text = @"拍照";
[titleLable setTextColor:[UIColor whiteColor]];
titleLable.textAlignment = NSTextAlignmentCenter;
[headerView addSubview:titleLable];
UIButton *headerBtn = [UIButton buttonWithType:UIButtonTypeCustom];
headerBtn.frame = CGRectMake(KWIDTH - 80 - 15, 12, 80, 40);
[headerBtn setTitle:@"取消" forState:UIControlStateNormal];
[headerBtn addTarget:self action:@selector(cancleCamera) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:headerBtn];
UIButton *swapBtn = [UIButton buttonWithType:UIButtonTypeCustom];
swapBtn.frame = CGRectMake(15, 12, 80, 40);
[swapBtn setTitle:@"切换" forState:UIControlStateNormal];
[swapBtn addTarget:self action:@selector(swapFrontAndBackCameras) forControlEvents:UIControlEventTouchUpInside];
[headerView addSubview:swapBtn];
[self.navigationController.navigationBar.subviews.lastObject setHidden:YES];
self.toolView = [[UIView alloc] initWithFrame:CGRectMake(0, KHEIGHT - 120, KWIDTH, 120)];
self.toolView.backgroundColor = [UIColor blackColor];
self.toolView.alpha = 0.8;
[self.mainLayout addSubview:self.toolView];
UIButton *cameraBtn = [UIButton buttonWithType:UIButtonTypeCustom];
cameraBtn.frame = CGRectMake((KWIDTH - 50)/2.0, (120 - 50)/ 2.0, 50, 50);
[cameraBtn setImage:[UIImage imageNamed:@"takePhoto"] forState:UIControlStateNormal];
[cameraBtn addTarget:self action:@selector(takePhotoButtonClick) forControlEvents:UIControlEventTouchUpInside];
[self.toolView addSubview:cameraBtn];
UIButton *photoBtn = [UIButton buttonWithType:UIButtonTypeCustom];
photoBtn.frame = CGRectMake(((KWIDTH / 2.0) - 30)/2.0, ((120) - 30)/ 2.0, 30, 30);
[photoBtn addTarget:self action:@selector(f_openPhotoAlbum) forControlEvents:UIControlEventTouchUpInside];
[photoBtn setImage:[UIImage imageNamed:@"cameraPhoto"] forState:UIControlStateNormal];
[self.toolView addSubview:photoBtn];
UIButton *lampBtn = [UIButton buttonWithType:UIButtonTypeCustom];
lampBtn.frame = CGRectMake(((KWIDTH / 2.0) - 30)/2.0 + (KWIDTH /2.0), ((120) - 30)/ 2.0, 30, 30);
[lampBtn setImage:[UIImage imageNamed:@"openFlish"] forState:UIControlStateSelected];
[lampBtn setImage:[UIImage imageNamed:@"closeFlish"] forState:UIControlStateNormal];
[lampBtn addTarget:self action:@selector(flashButtonClick:) forControlEvents:UIControlEventTouchUpInside];
[self.toolView addSubview:lampBtn];
self.previewLayer.frame = CGRectMake(0, 0,KWIDTH, KHEIGHT);
self.mainLayout.layer.masksToBounds = YES;
}
- (void)initAVCaptureSession{
self.session = [[AVCaptureSession alloc] init];
NSError *error;
self.effectiveScale = 1.0;
if (self.position == AVCaptureDevicePositionFront){
self.device = [self cameraWithPosition:AVCaptureDevicePositionFront];
}else{
self.device = [self cameraWithPosition:AVCaptureDevicePositionBack];
}
//更改这个设置的时候必须先锁定设备,修改完后再解锁,否则崩溃
[self.device lockForConfiguration:nil];
[self.device unlockForConfiguration];
self.videoInput = [[AVCaptureDeviceInput alloc] initWithDevice:self.device error:&error];
if (error) {
XNLog(@"%@",error);
self.session = nil;
[self.previewLayer removeFromSuperlayer];
self.stillImageOutput = nil;
}else{
self.stillImageOutput = [[AVCaptureStillImageOutput alloc] init];
//输出设置。AVVideoCodecJPEG 输出jpeg格式图片
NSDictionary * outputSettings = [[NSDictionary alloc] initWithObjectsAndKeys:AVVideoCodecJPEG,AVVideoCodecKey, nil];
[self.stillImageOutput setOutputSettings:outputSettings];
if ([self.session canAddInput:self.videoInput]) {
[self.session addInput:self.videoInput];
}
if ([self.session canAddOutput:self.stillImageOutput]) {
[self.session addOutput:self.stillImageOutput];
}
//初始化预览图层
self.previewLayer = [[AVCaptureVideoPreviewLayer alloc] initWithSession:self.session];
[self.previewLayer setVideoGravity:AVLayerVideoGravityResizeAspectFill];
[self resetFocusAndExposureModes];
}
}
- (void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:YES];
if (self.session) {
[self.session startRunning];
}
if(!isPostBack){
[self createdTool];
isPostBack = YES;
if(self.isOpenPhotoAlbum){
[self f_openPhotoAlbum];
}
}
}
- (void)viewDidDisappear:(BOOL)animated{
[super viewDidDisappear:YES];
if (self.session) {
[self.session stopRunning];
}
isPostBack = YES;
}
//自动聚焦、曝光
- (BOOL)resetFocusAndExposureModes{
AVCaptureExposureMode exposureMode = AVCaptureExposureModeContinuousAutoExposure;
AVCaptureFocusMode focusMode = AVCaptureFocusModeContinuousAutoFocus;
BOOL canResetFocus = [self.device isFocusPointOfInterestSupported] && [self.device isFocusModeSupported:focusMode];
BOOL canResetExposure = [self.device isExposurePointOfInterestSupported] && [self.device isExposureModeSupported:exposureMode];
CGPoint centerPoint = CGPointMake(0.5f, 0.5f);
NSError *error;
if ([self.device lockForConfiguration:&error]) {
if (canResetFocus) {
self.device.focusMode = focusMode;
self.device.focusPointOfInterest = centerPoint;
}
if (canResetExposure) {
self.device.exposureMode = exposureMode;
self.device.exposurePointOfInterest = centerPoint;
}
[self.device unlockForConfiguration];
return YES;
}
else{
XNLog(@"%@", error);
return NO;
}
}
- (void)touchesBegan:(NSSet<UITouch *> *)touches withEvent:(UIEvent *)event
{
UITouch *touch = touches.anyObject;
CGPoint point = [touch locationInView:self.mainLayout];
[self focusAtPoint:point];
}
//聚焦
- (void)focusAtPoint:(CGPoint)point {
if ([self cameraSupportsTapToFocus] && [self.device isFocusModeSupported:AVCaptureFocusModeAutoFocus]) {
NSError *error;
if ([self.device lockForConfiguration:&error]) {
self.device.focusPointOfInterest = point;
self.device.focusMode = AVCaptureFocusModeAutoFocus;
[self.device unlockForConfiguration];
}
else{
XNLog(@"%@", error);
}
}
}
-(void)changeDevicePropertySafety:(void (^)(AVCaptureDevice *captureDevice))propertyChange{
if ([self.device lockForConfiguration:nil]) {
propertyChange(self.device);
[self.device unlockForConfiguration];
}
}
- (BOOL)cameraSupportsTapToFocus {
return [self.device isFocusPointOfInterestSupported];
}
//获取设备方向
-(AVCaptureVideoOrientation)avOrientationForDeviceOrientation:(UIDeviceOrientation)deviceOrientation
{
AVCaptureVideoOrientation result = (AVCaptureVideoOrientation)deviceOrientation;
if ( deviceOrientation == UIDeviceOrientationLandscapeLeft )
result = AVCaptureVideoOrientationLandscapeRight;
else if ( deviceOrientation == UIDeviceOrientationLandscapeRight )
result = AVCaptureVideoOrientationLandscapeLeft;
return result;
}
//照相
- (void)takePhotoButtonClick {
if([self checkAvailable:UIImagePickerControllerSourceTypeCamera needShowMsg:YES]){
_stillImageConnection = [self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo];
UIDeviceOrientation curDeviceOrientation = [[UIDevice currentDevice] orientation];
AVCaptureVideoOrientation avcaptureOrientation = [self avOrientationForDeviceOrientation:curDeviceOrientation];
[_stillImageConnection setVideoOrientation:avcaptureOrientation];
[_stillImageConnection setPreferredVideoStabilizationMode:AVCaptureVideoStabilizationModeCinematic];
[_stillImageConnection setVideoScaleAndCropFactor:self.effectiveScale];
[self.stillImageOutput captureStillImageAsynchronouslyFromConnection:_stillImageConnection completionHandler:^(CMSampleBufferRef imageDataSampleBuffer, NSError *error) {
NSData *jpegData = [AVCaptureStillImageOutput jpegStillImageNSDataRepresentation:imageDataSampleBuffer];
[self jumpImageView:jpegData];
}];
}
}
//拍照之后调到相片详情页面
-(void)jumpImageView:(NSData*)data{
// [[xn_base_Handler_Alert_HUD sharedInstance] f_showLoadingHUD:self.mainLayout];
[SVProgressHUD show];
ClipViewController *viewController = [[ClipViewController alloc] init];
UIImage *image;
// 前置摄像头的情况下取镜像
if (self.device.position == AVCaptureDevicePositionFront) {
UIImageOrientation imgOrientation = UIImageOrientationLeftMirrored;
UIImage *t_image = [UIImage imageWithData:data];
image = [[UIImage alloc]initWithCGImage:t_image.CGImage scale:1.0f orientation:imgOrientation];
}else{
image = [UIImage imageWithData:data];
}
viewController.image = image;
viewController.picker = _imgPicker;
viewController.controller = self;
viewController.delegate = self;
viewController.isTakePhoto = YES;
isTakePhoto = YES;
viewController.cropAspectRatio = self.cropAspectRatio;
[self presentViewController:viewController animated:NO completion:^{
//[[xn_base_Handler_Alert_HUD sharedInstance] f_hideLoadingHUD];
[SVProgressHUD dismiss];
}];
}
- (void)cancleCamera
{
[self dismissViewControllerAnimated:YES completion:nil];
}
#pragma mark -- TakePhotoDelegate
- (void)takePhoto:(UIImage *)image
{
if (self.delegate && [self.delegate respondsToSelector:@selector(CameraTakePhoto:isTakePhoto:)]) {
[self dismissViewControllerAnimated:YES completion:nil];
[self.delegate CameraTakePhoto:image isTakePhoto:isTakePhoto];
}
}
//打开闪光灯
- (void)flashButtonClick:(UIButton *)sender {
sender.selected = !sender.selected;
if (sender.isSelected == YES) { //打开闪光灯
NSError *error = nil;
if ([self.device hasTorch]) {
BOOL locked = [self.device lockForConfiguration:&error];
if (locked) {
self.device.torchMode = AVCaptureTorchModeOn;
[self.device unlockForConfiguration];
}
}
}else{//关闭闪光灯
if ([self.device hasTorch]) {
[self.device lockForConfiguration:nil];
[self.device setTorchMode: AVCaptureTorchModeOff];
[self.device unlockForConfiguration];
}
}
}
//添加手势代理
- (void)setUpGesture
{
UIPinchGestureRecognizer *pinch = [[UIPinchGestureRecognizer alloc] initWithTarget:self action:@selector(handlePinchGesture:)];
pinch.delegate = self;
[self.mainLayout addGestureRecognizer:pinch];
}
//缩放手势 用于调整焦距
- (void)handlePinchGesture:(UIPinchGestureRecognizer *)recognizer{
BOOL allTouchesAreOnThePreviewLayer = YES;
NSUInteger numTouches = [recognizer numberOfTouches], i;
for ( i = 0; i < numTouches; ++i ) {
CGPoint location = [recognizer locationOfTouch:i inView:self.mainLayout];
CGPoint convertedLocation = [self.previewLayer convertPoint:location fromLayer:self.previewLayer.superlayer];
if ( ! [self.previewLayer containsPoint:convertedLocation] ) {
allTouchesAreOnThePreviewLayer = NO;
break;
}
}
if ( allTouchesAreOnThePreviewLayer ) {
self.effectiveScale = self.beginGestureScale * recognizer.scale;
if (self.effectiveScale < 1.0){
self.effectiveScale = 1.0;
}
XNLog(@"%f-------------->%f------------recognizerScale%f",self.effectiveScale,self.beginGestureScale,recognizer.scale);
CGFloat maxScaleAndCropFactor = [[self.stillImageOutput connectionWithMediaType:AVMediaTypeVideo] videoMaxScaleAndCropFactor];
XNLog(@"%f",maxScaleAndCropFactor);
if (self.effectiveScale > maxScaleAndCropFactor)
self.effectiveScale = maxScaleAndCropFactor;
[CATransaction begin];
[CATransaction setAnimationDuration:.025];
[self.previewLayer setAffineTransform:CGAffineTransformMakeScale(self.effectiveScale, self.effectiveScale)];
[CATransaction commit];
}
}
- (BOOL)gestureRecognizerShouldBegin:(UIGestureRecognizer *)gestureRecognizer
{
if ( [gestureRecognizer isKindOfClass:[UIPinchGestureRecognizer class]] ) {
self.beginGestureScale = self.effectiveScale;
}
return YES;
}
//打开相册
- (void)f_openPhotoAlbum
{
if([self checkAvailable:UIImagePickerControllerSourceTypePhotoLibrary needShowMsg:YES]){
[self openImagePickerControllerWithType:UIImagePickerControllerSourceTypePhotoLibrary];
}
}
/// 打开ImagePickerController的方法
- (void)openImagePickerControllerWithType:(UIImagePickerControllerSourceType)type
{
// 设备不可用 直接返回
if (![self checkAvailable:UIImagePickerControllerSourceTypePhotoLibrary needShowMsg:NO]) {
return;
}else {
// [[xn_base_Handler_Alert_HUD sharedInstance] f_showLoadingHUD:self.mainLayout];
[SVProgressHUD show];
_imgPicker = [[UIImagePickerController alloc] init];
_imgPicker.sourceType = type;
_imgPicker.navigationBar.translucent = NO;
_imgPicker.delegate = self;
_imgPicker.allowsEditing = NO;
[self presentViewController:_imgPicker animated:YES completion:^{
// [[xn_base_Handler_Alert_HUD sharedInstance] f_hideLoadingHUD];
[SVProgressHUD dismiss];
}];
}
}
- (BOOL)checkAvailable:(UIImagePickerControllerSourceType)type needShowMsg:(BOOL)needShowMsg
{
if ([UIImagePickerController isSourceTypeAvailable:type]) {
return YES;
}else{
if (needShowMsg) {
NSString *template = nil;
NSString *deviceType = ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) ? @"iPad" : @"iPhone";
switch (type) {
// 目前把图库和相册同样对待
case UIImagePickerControllerSourceTypePhotoLibrary:
case UIImagePickerControllerSourceTypeSavedPhotosAlbum:
//template = NSLocalizedString(@"string_0142", nil);
template = @"您的%@相册当前不可用,请检查后重试!";
break;
// 相机
case UIImagePickerControllerSourceTypeCamera:
template = @"您的%@相机当前不可用,请检查后重试!";
// template = NSLocalizedString(@"string_0141", nil);
break;
default:
break;
}
if(template != nil) {
[[AlertHandler sharedInstance] f_showAlert_default_title:@"提示" message:[NSString stringWithFormat:template,deviceType] confirmHandler:nil confirmTitle:@"我知道了" target:self];
// [[xn_base_Handler_Alert_HUD sharedInstance] f_showAlert_default_title:NSLocalizedString(@"string_0009", nil) message:[NSString stringWithFormat:template,deviceType] confirmHandler:nil confirmTitle:NSLocalizedString(@"string_0011", nil) target:self];
}
}
return NO;
}
}
-(BOOL) isFrontCameraAvailable{
return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront];
}
-(BOOL) isRearCameraAvailable{
return [UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear];
}
-(BOOL) hasMultipleCameras {
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
if (devices != nil && [devices count] > 1) {
return YES;
}else{
return NO;
}
}
-(AVCaptureDevice *)cameraWithPosition : (AVCaptureDevicePosition) position
{
NSArray *devices = [AVCaptureDevice devicesWithMediaType:AVMediaTypeVideo];
for (AVCaptureDevice *device in devices ){
if ( device.position == position ){
return device;
}
}
return nil ;
}
-(void) swapFrontAndBackCameras {
//check for available cameras!
if (![self hasMultipleCameras]) {
return;
}else{
NSArray *inputs = self.session.inputs;
for ( AVCaptureDeviceInput *input in inputs ) {
AVCaptureDevice *device = input.device;
if ( [device hasMediaType:AVMediaTypeVideo] ) {
AVCaptureDevicePosition position = device.position;
if (position == AVCaptureDevicePositionFront){
self.device = [self cameraWithPosition:AVCaptureDevicePositionBack];
}else{
self.device = [self cameraWithPosition:AVCaptureDevicePositionFront];
}
self.videoInput = [AVCaptureDeviceInput deviceInputWithDevice:self.device error:nil];
// beginConfiguration ensures that pending changes are not applied immediately
[self.session beginConfiguration];
[self.session removeInput:input];
[self.session addInput:self.videoInput];
// Changes take effect once the outermost commitConfiguration is invoked.
[self.session commitConfiguration];
break;
}
}
}
}
#pragma mark - UINavigationControllerDelegate, UIImagePickerControllerDelegate
// 选择照片之后
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary<NSString *,id> *)info
{
UIImage *image = info[UIImagePickerControllerOriginalImage];
[picker dismissViewControllerAnimated:YES completion:^() {
[self cropImage:image];
}];
}
- (void)cropImage: (UIImage *)image {
ClipViewController *viewController = [[ClipViewController alloc] init];
viewController.image = image;
viewController.picker = _imgPicker;
viewController.controller = self;
viewController.delegate = self;
viewController.isTakePhoto = NO;
isTakePhoto = NO;
viewController.cropAspectRatio = self.cropAspectRatio;
[self presentViewController:viewController animated:NO completion:^{
//[[xn_base_Handler_Alert_HUD sharedInstance] f_hideLoadingHUD];
[SVProgressHUD dismiss];
}];
}
#pragma mark -- ClipPhotoDelegate
- (void)clipPhoto:(UIImage *)image
{
if (self.delegate && [self.delegate respondsToSelector:@selector(CameraTakePhoto:isTakePhoto:)]) {
[self dismissViewControllerAnimated:YES completion:nil];
[self.delegate CameraTakePhoto:image isTakePhoto:isTakePhoto];
}
}
/**
屏幕方向 >=6.0
*/
- (UIInterfaceOrientationMask)supportedInterfaceOrientations {
return UIInterfaceOrientationMaskPortrait;
}
- (UIInterfaceOrientation)preferredInterfaceOrientationForPresentation {
return UIInterfaceOrientationPortrait;
}
- (BOOL)shouldAutorotate {
return NO;
}
/**
状态条样式 >=7.0
*/
- (UIStatusBarStyle)preferredStatusBarStyle {
return UIStatusBarStyleLightContent;
}
/**
是否隐藏状态条 >=7.0
*/
- (BOOL)prefersStatusBarHidden {
return YES;
}
/**
内存预警
*/
- (void)didReceiveMemoryWarning {
// Releases the view if it doesn't have a superview.
[super didReceiveMemoryWarning];
// Release any cached data, images, etc that aren't in use.
}
@end