blob: 177c1901b331fed3ff34579e0d2b1cce19e7572f (
plain)
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
|
//
// EmbedReaderViewController.m
// EmbedReader
//
// Created by spadix on 5/2/11.
//
#import "EmbedReaderViewController.h"
@implementation EmbedReaderViewController
@synthesize readerView, resultText;
- (void) cleanup
{
[cameraSim release];
cameraSim = nil;
readerView.readerDelegate = nil;
[readerView release];
readerView = nil;
[resultText release];
resultText = nil;
}
- (void) dealloc
{
[self cleanup];
[super dealloc];
}
- (void) viewDidLoad
{
[super viewDidLoad];
// the delegate receives decode results
readerView.readerDelegate = self;
// ensure initial camera orientation is correctly set
UIApplication *app = [UIApplication sharedApplication];
[readerView willRotateToInterfaceOrientation: app.statusBarOrientation
duration: 0];
// you can use this to support the simulator
if(TARGET_IPHONE_SIMULATOR) {
cameraSim = [[ZBarCameraSimulator alloc]
initWithViewController: self];
cameraSim.readerView = readerView;
}
}
- (void) viewDidUnload
{
[self cleanup];
[super viewDidUnload];
}
- (BOOL) shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation) orient
{
// auto-rotation is supported
return(YES);
}
- (void) willRotateToInterfaceOrientation: (UIInterfaceOrientation) orient
duration: (NSTimeInterval) duration
{
// compensate for view rotation so camera preview is not rotated
[readerView willRotateToInterfaceOrientation: orient
duration: duration];
}
- (void) willAnimateRotationToInterfaceOrientation: (UIInterfaceOrientation) orient
duration: (NSTimeInterval) duration
{
// perform rotation in animation loop so camera preview does not move
// wrt device orientation
[readerView setNeedsLayout];
}
- (void) viewDidAppear: (BOOL) animated
{
// run the reader when the view is visible
[readerView start];
}
- (void) viewWillDisappear: (BOOL) animated
{
[readerView stop];
}
- (void) readerView: (ZBarReaderView*) view
didReadSymbols: (ZBarSymbolSet*) syms
fromImage: (UIImage*) img
{
// do something useful with results
for(ZBarSymbol *sym in syms) {
resultText.text = sym.data;
break;
}
}
@end
|