forked from card-io/card.io-iOS-source
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCardIOCameraView.mm
569 lines (475 loc) · 21.5 KB
/
CardIOCameraView.mm
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
//
// CardIOCameraView.m
// See the file "LICENSE.md" for the full license governing this code.
//
#if USE_CAMERA || SIMULATE_CAMERA
#import "CardIOAnimation.h"
#import "CardIOBundle.h"
#import "CardIOCameraView.h"
#import "CardIOCardScanner.h"
#import "CardIOCGGeometry.h"
#import "CardIOConfig.h"
#import "CardIOMacros.h"
#import "CardIOOrientation.h"
#import "CardIOPaymentViewControllerContinuation.h"
#import "CardIOReadCardInfo.h"
#import "CardIOResource.h"
#import "CardIOShutterView.h"
#import "CardIOStyles.h"
#import "CardIOVideoFrame.h"
#import "CardIOVideoStream.h"
#import "CardIOLocalizer.h"
#define kLogoAlpha 0.6f
#define kGuideLayerTextAlpha 0.6f
#define kGuideLayerTextColor [UIColor colorWithWhite:1.0f alpha:kGuideLayerTextAlpha]
#define kLabelVisibilityAnimationDuration 0.3f
#define kRotationLabelShowDelay (kRotationAnimationDuration + 0.1f)
#define kStandardInstructionsFontSize 18.0f
#define kMinimumInstructionsFontSize (kStandardInstructionsFontSize / 2)
@interface CardIOCameraView ()
@property(nonatomic, strong, readonly) CardIOGuideLayer *cardGuide;
@property(nonatomic, strong, readwrite) UILabel *guideLayerLabel;
@property(nonatomic, strong, readwrite) CardIOShutterView *shutter;
@property(nonatomic, strong, readwrite) CardIOVideoStream *videoStream;
@property(nonatomic, strong, readwrite) UIButton *lightButton;
@property(nonatomic, strong, readwrite) UIImageView *logoView;
@property(nonatomic, assign, readwrite) UIDeviceOrientation deviceOrientation;
@property(nonatomic, assign, readwrite) BOOL rotatingInterface;
@property(nonatomic, assign, readwrite) BOOL videoStreamSessionWasRunningBeforeRotation;
@property(nonatomic, strong, readwrite) CardIOConfig *config;
@property(nonatomic, assign, readwrite) BOOL hasLaidoutCameraButtons;
#if CARDIO_DEBUG
@property(nonatomic, strong, readwrite) UITextField *debugTextField;
#endif
@end
#pragma mark -
@implementation CardIOCameraView
+ (CGRect)previewRectWithinSize:(CGSize)size landscape:(BOOL)landscape {
CGSize contents;
if(landscape) {
contents = CGSizeMake(kLandscapeSampleWidth, kLandscapeSampleHeight);
} else {
contents = CGSizeMake(kPortraitSampleWidth, kPortraitSampleHeight);
}
CGRect contentsRect = aspectFit(contents, size);
return CGRectFlooredToNearestPixel(contentsRect);
}
- (id)initWithFrame:(CGRect)frame {
[NSException raise:@"Wrong initializer" format:@"CardIOCameraView's designated initializer is initWithFrame:delegate:config:"];
return nil;
}
- (id)initWithFrame:(CGRect)frame delegate:(id<CardIOVideoStreamDelegate>)delegate config:(CardIOConfig *)config {
self = [super initWithFrame:frame];
if(self) {
_deviceOrientation = UIDeviceOrientationUnknown;
self.autoresizingMask = UIViewAutoresizingNone;
self.backgroundColor = [UIColor clearColor];
self.clipsToBounds = YES;
_delegate = delegate;
_config = config;
_videoStream = [[CardIOVideoStream alloc] init];
self.videoStream.config = config;
self.videoStream.delegate = self;
self.videoStream.previewLayer.needsDisplayOnBoundsChange = YES;
self.videoStream.previewLayer.contentsGravity = kCAGravityResizeAspect;
#if USE_CAMERA
self.videoStream.previewLayer.videoGravity = AVLayerVideoGravityResizeAspectFill;
#endif
// These settings are helpful when debugging rotation/bounds/rendering issues:
// self.videoStream.previewLayer.backgroundColor = [UIColor yellowColor].CGColor;
// Preview of the camera image
[self.layer addSublayer:self.videoStream.previewLayer];
// Guide layer shows card guide edges and other progress feedback directly related to the camera contents
_cardGuide = [[CardIOGuideLayer alloc] initWithDelegate:self];
self.cardGuide.contentsGravity = kCAGravityResizeAspect;
self.cardGuide.needsDisplayOnBoundsChange = YES;
self.cardGuide.animationDuration = kRotationAnimationDuration;
self.cardGuide.deviceOrientation = self.deviceOrientation;
self.cardGuide.guideColor = config.guideColor;
[self.layer addSublayer:self.cardGuide];
NSString *scanInstructions = nil;
scanInstructions = config.scanInstructions;
if(!scanInstructions) {
scanInstructions = CardIOLocalizedString(@"scan_guide", config.languageOrLocale); // Hold credit card here.\nIt will scan automatically.
}
_guideLayerLabel = [[UILabel alloc] initWithFrame:CGRectZero];
self.guideLayerLabel.text = scanInstructions;
self.guideLayerLabel.textAlignment = NSTextAlignmentCenter;
self.guideLayerLabel.backgroundColor = [UIColor clearColor];
self.guideLayerLabel.textColor = kGuideLayerTextColor;
self.guideLayerLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:kStandardInstructionsFontSize];
self.guideLayerLabel.numberOfLines = 0;
[self addSubview:self.guideLayerLabel];
// Shutter view for shutter-open animation
_shutter = [[CardIOShutterView alloc] initWithFrame:CGRectZero];
[self.shutter setOpen:NO animated:NO duration:0];
[self addSubview:self.shutter];
// Tap-to-refocus support
if([self.videoStream hasAutofocus]) {
UITapGestureRecognizer *touch = [[UITapGestureRecognizer alloc] initWithTarget:self action:@selector(refocus)];
[self addGestureRecognizer:touch];
}
// Set up the light button
if([self.videoStream hasTorch] && ![self.videoStream canSetTorchLevel]) {
_lightButton = [CardIOResource lightButton];
self.lightButton.accessibilityLabel = CardIOLocalizedString(@"activate_flash", config.languageOrLocale); // Turn flash on.
[self.lightButton addTarget:self action:@selector(toggleTorch:) forControlEvents:UIControlEventTouchUpInside];
[self addSubview:self.lightButton];
}
// Set up logo
NSString *logoImageName = config.useCardIOLogo ? @"card_io_logo.png" : @"paypal_logo.png";
_logoView = [[UIImageView alloc] initWithImage:[[CardIOBundle sharedInstance] imageNamed:logoImageName]];
self.logoView.alpha = kLogoAlpha;
self.logoView.isAccessibilityElement = YES;
self.logoView.accessibilityLabel = (config.useCardIOLogo
? CardIOLocalizedString(@"card_io_logo",config.languageOrLocale) // card.io
: CardIOLocalizedString(@"paypal_logo", config.languageOrLocale)); // PayPal
[self addSubview:self.logoView];
#if CARDIO_DEBUG
// This can be useful for debugging dynamic changes, such as brightness, torch setting, etc.
// _debugTextField = [[UITextField alloc] initWithFrame:CGRectMake(0, 0, 300, 20)];
// _debugTextField.textColor = [UIColor greenColor];
// _debugTextField.font = [UIFont fontWithName:@"Helvetica-Bold" size:14.0f];
// _debugTextField.backgroundColor = [UIColor clearColor];
// [self addSubview:_debugTextField];
#endif
if(config.hideCardIOLogo) {
[self.logoView removeFromSuperview]; // merely setting .hidden requires that we maintain this during rotations, etc. :(
}
UIView *scanOverlayView = config.scanOverlayView;
if(scanOverlayView) {
[self addSubview:scanOverlayView];
}
}
return self;
}
- (void)startVideoStreamSession {
[self.videoStream startSession];
// If we don't do this, then when the torch was on, and the card read failed,
// it still shows as on when this view is re-displayed, even though the ending
// of the session turned it off.
[self updateLightButtonState];
}
- (void)stopVideoStreamSession {
[self.videoStream stopSession];
[self.shutter setOpen:NO animated:NO duration:0.0f];
}
- (void)refocus {
[self.videoStream refocus];
}
- (CardIOCardScanner *)scanner {
return self.videoStream.scanner;
}
- (void)setSuppressFauxCardLayer:(BOOL)suppressFauxCardLayer {
if(suppressFauxCardLayer) {
self.cardGuide.fauxCardLayer.hidden = YES;
}
_suppressFauxCardLayer = suppressFauxCardLayer;
}
- (CGRect)guideFrame {
return [self.cardGuide guideFrame];
}
- (CGRect)cameraPreviewFrame {
CGRect cameraPreviewFrame = [[self class] previewRectWithinSize:self.bounds.size
landscape:UIInterfaceOrientationIsLandscape([UIApplication sharedApplication].statusBarOrientation)];
return cameraPreviewFrame;
}
- (void)layoutSubviews {
[self updateCameraOrientation];
CGRect cameraPreviewFrame = [self cameraPreviewFrame];
SuppressCAAnimation(^{
if (!CGRectEqualToRect(self.videoStream.previewLayer.frame, cameraPreviewFrame)) {
self.videoStream.previewLayer.frame = cameraPreviewFrame;
}
self.shutter.frame = cameraPreviewFrame;
[self layoutCameraButtons];
self.cardGuide.frame = cameraPreviewFrame;
});
}
- (void)toggleTorch:(UIButton *)theButton {
CardIOLog(@"Manual torch change");
BOOL torchWasOn = [self.videoStream torchIsOn];
BOOL success = [self.videoStream setTorchOn:!torchWasOn];
if (success) {
[self updateLightButtonState];
}
}
- (void)updateLightButtonState {
if (self.lightButton) {
BOOL torchIsOn = [self.videoStream torchIsOn];
[self.lightButton setImage:[CardIOResource boltImageForTorchOn:torchIsOn] forState:UIControlStateNormal];
self.lightButton.accessibilityLabel = torchIsOn ?
CardIOLocalizedString(@"deactivate_flash", self.config.languageOrLocale) : // Turn flash off.
CardIOLocalizedString(@"activate_flash", self.config.languageOrLocale); // Turn flash on.
}
}
- (void)layoutCameraButtons {
self.hasLaidoutCameraButtons = YES;
CGRect cameraPreviewFrame = [self cameraPreviewFrame];
// Hide the buttons when the view is really, really small
#define kButtonGreekingThreshold 200
SuppressCAAnimation(^{
if (cameraPreviewFrame.size.width < kButtonGreekingThreshold || self.rotatingInterface) {
self.logoView.hidden = YES;
self.lightButton.hidden = YES;
#if CARDIO_DEBUG
_debugTextField.hidden = YES;
#endif
} else {
self.logoView.hidden = NO;
self.lightButton.hidden = NO;
#if CARDIO_DEBUG
_debugTextField.hidden = NO;
#endif
}
});
self.logoView.frame = CGRectWithXYAndSize(cameraPreviewFrame.size.width + cameraPreviewFrame.origin.x - self.logoView.frame.size.width - 10.0f,
cameraPreviewFrame.origin.y + 10.0f,
self.logoView.frame.size);
self.lightButton.frame = CGRectWithXYAndSize(cameraPreviewFrame.origin.x + 10.0f,
cameraPreviewFrame.origin.y + 10.0f,
self.lightButton.frame.size);
InterfaceToDeviceOrientationDelta delta = orientationDelta([UIApplication sharedApplication].statusBarOrientation, self.deviceOrientation);
CGFloat rotation = -rotationForOrientationDelta(delta); // undo the orientation delta
CGAffineTransform r = CGAffineTransformMakeRotation(rotation);
self.logoView.transform = r;
self.lightButton.transform = r;
#if CARDIO_DEBUG
_debugTextField.frame = CGRectWithXYAndSize(cameraPreviewFrame.origin.x + 10.0f,
cameraPreviewFrame.origin.y + cameraPreviewFrame.size.height - _debugTextField.frame.size.height - 10.0f,
_debugTextField.frame.size);
switch (delta) {
case InterfaceToDeviceOrientationSame: {
_debugTextField.transform = CGAffineTransformTranslate(r, 70.0f, 64.0f);
_debugTextField.textAlignment = NSTextAlignmentLeft;
break;
}
case InterfaceToDeviceOrientationRotatedClockwise: {
_debugTextField.transform = CGAffineTransformTranslate(r, -20.0f, 24.0f);
_debugTextField.textAlignment = NSTextAlignmentRight;
break;
}
case InterfaceToDeviceOrientationUpsideDown: {
_debugTextField.transform = CGAffineTransformTranslate(r, 70.0f, 64.0f);
_debugTextField.textAlignment = NSTextAlignmentRight;
break;
}
case InterfaceToDeviceOrientationRotatedCounterclockwise: {
_debugTextField.transform = CGAffineTransformTranslate(r, 20.0f, -24.0f);
_debugTextField.textAlignment = NSTextAlignmentLeft;
break;
}
default: {
break;
}
}
#endif
}
- (void)showGuideLabel {
// If we are rotating, let it stay hidden; the interface rotation cleanup code will re-show it
if(!self.rotatingInterface) {
self.guideLayerLabel.hidden = NO;
}
}
- (void)orientGuideLayerLabel {
InterfaceToDeviceOrientationDelta delta = orientationDelta([UIApplication sharedApplication].statusBarOrientation, self.deviceOrientation);
CGFloat rotation = -rotationForOrientationDelta(delta); // undo the orientation delta
self.guideLayerLabel.transform = CGAffineTransformMakeRotation(rotation);
}
#pragma mark - Orientation
- (void)willAppear {
[[NSNotificationCenter defaultCenter] addObserver:self
selector:@selector(didReceiveDeviceOrientationNotification:)
name:UIDeviceOrientationDidChangeNotification
object:[UIDevice currentDevice]];
[[UIDevice currentDevice] beginGeneratingDeviceOrientationNotifications];
self.deviceOrientation = UIDeviceOrientationUnknown;
[self didReceiveDeviceOrientationNotification:nil];
[self.videoStream willAppear];
[self becomeFirstResponder];
}
- (void)willDisappear {
[self.videoStream willDisappear];
[[UIDevice currentDevice] endGeneratingDeviceOrientationNotifications];
[[NSNotificationCenter defaultCenter] removeObserver:self];
}
- (void)didReceiveDeviceOrientationNotification:(NSNotification *)notification {
UIDeviceOrientation newDeviceOrientation;
switch ([UIDevice currentDevice].orientation) {
case UIDeviceOrientationPortrait:
newDeviceOrientation = UIDeviceOrientationPortrait;
break;
case UIDeviceOrientationPortraitUpsideDown:
newDeviceOrientation = UIDeviceOrientationPortraitUpsideDown;
break;
case UIDeviceOrientationLandscapeLeft:
newDeviceOrientation = UIDeviceOrientationLandscapeLeft;
break;
case UIDeviceOrientationLandscapeRight:
newDeviceOrientation = UIDeviceOrientationLandscapeRight;
break;
default:
if (self.deviceOrientation == UIDeviceOrientationUnknown) {
CardIOPaymentViewController *vc = [CardIOPaymentViewController cardIOPaymentViewControllerForResponder:self];
if (vc) {
newDeviceOrientation = (UIDeviceOrientation)vc.initialInterfaceOrientationForViewcontroller;
}
else {
newDeviceOrientation = UIDeviceOrientationPortrait;
}
}
else {
newDeviceOrientation = self.deviceOrientation;
}
break;
}
if (![self isSupportedOverlayOrientation:(UIInterfaceOrientation)newDeviceOrientation]) {
if ([self isSupportedOverlayOrientation:(UIInterfaceOrientation)self.deviceOrientation]) {
newDeviceOrientation = self.deviceOrientation;
}
else {
UIInterfaceOrientation orientation = [self defaultSupportedOverlayOrientation];
if (orientation != UIInterfaceOrientationUnknown) {
newDeviceOrientation = (UIDeviceOrientation)orientation;
}
}
}
if(newDeviceOrientation != self.deviceOrientation) {
self.deviceOrientation = newDeviceOrientation;
[self.cardGuide didRotateToDeviceOrientation:self.deviceOrientation];
if (self.hasLaidoutCameraButtons) {
[UIView animateWithDuration:kRotationAnimationDuration animations:^{[self layoutCameraButtons];}];
}
else {
[self layoutCameraButtons];
}
self.guideLayerLabel.hidden = YES;
[self performSelector:@selector(showGuideLabel) withObject:nil afterDelay:kRotationLabelShowDelay];
[self setNeedsLayout];
if(self.config.scanOverlayView && !self.rotatingInterface) {
NSDictionary *info = @{CardIOCurrentScanningOrientation: @(newDeviceOrientation),
CardIOScanningOrientationAnimationDuration: @(kRotationAnimationDuration)};
[[NSNotificationCenter defaultCenter] postNotificationName:CardIOScanningOrientationDidChangeNotification
object:self
userInfo:info];
}
}
}
- (void)updateCameraOrientation {
// We want the camera to appear natural. That means that the camera preview should match reality, orientationwise.
// If the interfaceOrientation isn't portrait, then we need to rotate the preview precisely OPPOSITE the interface.
CGFloat rotation = -orientationToRotation([UIApplication sharedApplication].statusBarOrientation);
CATransform3D transform = CATransform3DIdentity;
transform = CATransform3DRotate(transform, rotation, 0, 0, 1);
// NSLog(@"Updating camera orientation for interface orientation %@, device orientation %@: Rotation %f",
// INTERFACE_LANDSCAPE_OR_PORTRAIT([UIApplication sharedApplication].statusBarOrientation),
// DEVICE_LANDSCAPE_OR_PORTRAIT(self.deviceOrientation),
// rotation * 180 / M_PI);
SuppressCAAnimation(^{
self.videoStream.previewLayer.transform = transform;
});
}
#if SIMULATE_CAMERA
#pragma mark - Shake gesture for simulated camera view
- (void)motionEnded:(UIEventSubtype)motion withEvent:(UIEvent *)event {
if (event.subtype == UIEventSubtypeMotionShake) {
[self.videoStream considerItScanned];
}
if ([super respondsToSelector:@selector(motionEnded:withEvent:)]) {
[super motionEnded:motion withEvent:event];
}
}
- (BOOL)canBecomeFirstResponder {
return YES;
}
#endif
#pragma mark - CardIOGuideLayerDelegate method
- (void)guideLayerDidLayout:(CGRect)internalGuideFrame {
CGFloat width = MAX(internalGuideFrame.size.width, internalGuideFrame.size.height);
CGFloat height = MIN(internalGuideFrame.size.width, internalGuideFrame.size.height);
CGRect internalGuideRect = CGRectZeroWithSize(CGSizeMake(width, height));
self.guideLayerLabel.bounds = internalGuideRect;
[self.guideLayerLabel sizeToFit];
CGRect cameraPreviewFrame = [self cameraPreviewFrame];
self.guideLayerLabel.center = CGPointMake(CGRectGetMidX(cameraPreviewFrame), CGRectGetMidY(cameraPreviewFrame));
internalGuideRect.size.height = 9999.9f;
CGRect textRect = [self.guideLayerLabel textRectForBounds:internalGuideRect limitedToNumberOfLines:0];
while (textRect.size.height > height && self.guideLayerLabel.font.pointSize > kMinimumInstructionsFontSize) {
self.guideLayerLabel.font = [UIFont fontWithName:self.guideLayerLabel.font.fontName size:self.guideLayerLabel.font.pointSize - 1];
textRect = [self.guideLayerLabel textRectForBounds:internalGuideRect limitedToNumberOfLines:0];
}
[self orientGuideLayerLabel];
}
#pragma mark - CardIOVideoStreamDelegate methods
- (void)videoStream:(CardIOVideoStream *)stream didProcessFrame:(CardIOVideoFrame *)processedFrame {
[self.shutter setOpen:YES animated:YES duration:0.5f];
// Hide instructions once we start to find edges
if (processedFrame.numEdgesFound < 0.05f) {
[UIView animateWithDuration:kLabelVisibilityAnimationDuration animations:^{self.guideLayerLabel.alpha = 1.0f;}];
} else if (processedFrame.numEdgesFound > 2.1f) {
[UIView animateWithDuration:kLabelVisibilityAnimationDuration animations:^{self.guideLayerLabel.alpha = 0.0f;}];
}
// Pass the video frame to the cardGuide so that it can update the edges
self.cardGuide.videoFrame = processedFrame;
#if CARDIO_DEBUG
static NSTimeInterval lastUpdated = 0;
NSTimeInterval now = [[NSDate date] timeIntervalSince1970];
if (now - lastUpdated > 0.25) {
lastUpdated = now;
if (![processedFrame.debugString isEqualToString:_debugTextField.text]) {
_debugTextField.text = processedFrame.debugString;
}
}
#endif
[self.delegate videoStream:stream didProcessFrame:processedFrame];
}
// Overlay orientation has the same constraints as the view controller,
// unless self.config.allowFreelyRotatingCardGuide == YES.
- (UIInterfaceOrientationMask)supportedOverlayOrientationsMask {
UIInterfaceOrientationMask supportedOverlayOrientationsMask = UIInterfaceOrientationMaskAll;
CardIOPaymentViewController *vc = [CardIOPaymentViewController cardIOPaymentViewControllerForResponder:[self nextResponder]];
if (vc) {
supportedOverlayOrientationsMask = [vc supportedOverlayOrientationsMask];
}
else if (!self.config.allowFreelyRotatingCardGuide) {
// We must be inside a raw CardIOView, without a CardIOPaymentViewController.
UIResponder *responder = [self nextResponder];
while (responder && ![responder isKindOfClass:[UIViewController class]]) {
responder = [responder nextResponder];
}
if (responder) {
supportedOverlayOrientationsMask = [((UIViewController *)responder) supportedInterfaceOrientations];
}
}
return supportedOverlayOrientationsMask;
}
- (BOOL)isSupportedOverlayOrientation:(UIInterfaceOrientation)orientation {
return (([self supportedOverlayOrientationsMask] & (1 << orientation)) != 0);
}
- (UIInterfaceOrientation)defaultSupportedOverlayOrientation {
if (self.config.allowFreelyRotatingCardGuide) {
return UIInterfaceOrientationPortrait;
}
else {
UIInterfaceOrientation defaultOrientation = UIInterfaceOrientationUnknown;
UIInterfaceOrientationMask supportedOverlayOrientationsMask = [self supportedOverlayOrientationsMask];
for (NSInteger orientation = UIInterfaceOrientationPortrait;
orientation <= UIInterfaceOrientationLandscapeRight;
orientation++) {
if ((supportedOverlayOrientationsMask & (1 << orientation)) != 0) {
defaultOrientation = (UIInterfaceOrientation)orientation;
break;
}
}
return defaultOrientation;
}
}
#pragma mark - Manual property implementations
- (UIFont *)instructionsFont {
return self.guideLayerLabel.font;
}
- (void)setInstructionsFont:(UIFont *)instructionsFont {
self.guideLayerLabel.font = instructionsFont;
}
@end
#endif