summaryrefslogtreecommitdiffstats
path: root/iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m
diff options
context:
space:
mode:
Diffstat (limited to 'iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m')
-rw-r--r--iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m101
1 files changed, 101 insertions, 0 deletions
diff --git a/iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m b/iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m
new file mode 100644
index 0000000..177c190
--- /dev/null
+++ b/iphone/examples/EmbedReader/EmbedReader/EmbedReaderViewController.m
@@ -0,0 +1,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