Created
March 26, 2015 21:54
-
-
Save jonstoked/43cb9674183f984c1006 to your computer and use it in GitHub Desktop.
FastttCamera Landscape Lock Problem
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
// | |
// CameraViewController.m | |
// Scavenger | |
// | |
// Created by Jon Stokes on 3/20/15. | |
// Copyright (c) 2015 FarFaria. All rights reserved. | |
// | |
#import "CameraViewController.h" | |
#import "PhotoViewController.h" | |
#import "Speech.h" | |
@interface CameraViewController () | |
@property (nonatomic, strong) FastttCamera *fastCamera; | |
@property (nonatomic) BOOL taking; | |
@property (nonatomic, strong) UIPageViewController *pageViewController; | |
@property (nonatomic, weak) IBOutlet UIButton *takeButton; | |
@property (nonatomic, weak) IBOutlet UIButton *closeButton; | |
@end | |
@implementation CameraViewController | |
- (void)viewDidLoad { | |
[super viewDidLoad]; | |
_fastCamera = [FastttCamera new]; | |
_fastCamera.delegate = self; | |
_fastCamera.interfaceRotatesWithOrientation = NO; | |
_fastCamera.returnsRotatedPreview = NO; | |
[self fastttAddChildViewController:_fastCamera belowSubview:_takeButton]; | |
_fastCamera.view.frame = self.view.frame; | |
_takeButton.layer.shadowOpacity = 0.7; | |
_takeButton.layer.shadowRadius = 1.0; | |
_takeButton.layer.shadowColor = [UIColor blackColor].CGColor; | |
_takeButton.layer.shadowOffset = CGSizeMake(0.5, 0.5); | |
_closeButton.layer.shadowOpacity = _takeButton.layer.shadowOpacity; | |
_closeButton.layer.shadowRadius = _takeButton.layer.shadowRadius; | |
_closeButton.layer.shadowColor = _takeButton.layer.shadowColor; | |
_closeButton.layer.shadowOffset = _takeButton.layer.shadowOffset; | |
[self setupPageViewController]; | |
} | |
-(void)viewWillAppear:(BOOL)animated { | |
[super viewWillAppear:animated]; | |
[self.navigationController setNavigationBarHidden:YES animated:YES]; | |
} | |
-(void)setupPageViewController { | |
_pageViewController = [self.storyboard instantiateViewControllerWithIdentifier:@"PageViewController"]; | |
_pageViewController.dataSource = self; | |
_pageViewController.delegate = self; | |
PhotoViewController *startingViewController = [self viewControllerAtIndex:_currentItemIndex]; | |
NSArray *viewControllers = @[startingViewController]; | |
[self.pageViewController setViewControllers:viewControllers direction:UIPageViewControllerNavigationDirectionForward animated:NO completion:nil]; | |
[self.view insertSubview:_pageViewController.view belowSubview:_takeButton]; | |
[self updateState]; | |
} | |
-(PhotoViewController*)viewControllerAtIndex:(NSUInteger)index { | |
if (([_hunt.items count] == 0) || (index >= [_hunt.items count])) { | |
return nil; | |
} | |
PhotoViewController *photoVC = [self.storyboard instantiateViewControllerWithIdentifier:@"PhotoViewController"]; | |
[photoVC view]; //instantiate subviews | |
photoVC.item = _hunt.items[index]; | |
photoVC.pageIndex = index; | |
return photoVC; | |
} | |
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerBeforeViewController:(UIViewController *)viewController | |
{ | |
NSUInteger index = ((PhotoViewController*) viewController).pageIndex; | |
if ((index == 0) || (index == NSNotFound)) { | |
return nil; | |
} | |
index--; | |
return [self viewControllerAtIndex:index]; | |
} | |
- (UIViewController *)pageViewController:(UIPageViewController *)pageViewController viewControllerAfterViewController:(UIViewController *)viewController | |
{ | |
NSUInteger index = ((PhotoViewController*) viewController).pageIndex; | |
if (index == NSNotFound) { | |
return nil; | |
} | |
index++; | |
return [self viewControllerAtIndex:index]; | |
} | |
- (void)pageViewController:(UIPageViewController *)pageViewController | |
didFinishAnimating:(BOOL)finished | |
previousViewControllers:(NSArray *)previousViewControllers | |
transitionCompleted:(BOOL)completed { | |
if(completed) { | |
PhotoViewController *photoVC = (PhotoViewController*)_pageViewController.viewControllers[0]; | |
_currentItemIndex = photoVC.pageIndex; | |
[self updateState]; | |
} | |
} | |
-(Item*)currentItem { | |
Item *item = (Item*)_hunt.items[_currentItemIndex]; | |
return item; | |
} | |
-(void)updateState { | |
if(self.currentItem.hasImage) { | |
_state = Review; | |
[_takeButton setTitle:@"RESNAP" forState:UIControlStateNormal]; | |
} else { | |
_state = Capture; | |
[_takeButton setTitle:@"SNAP" forState:UIControlStateNormal]; | |
} | |
[[Speech sharedManager] speak:self.currentItem.name]; | |
_taking = NO; | |
} | |
-(IBAction)takePicture:(id)sender { | |
if(!_taking) { | |
_taking = YES; | |
if(_state == Review) { | |
[self trashImage]; | |
[self updateState]; | |
} else { | |
[_fastCamera takePicture]; | |
} | |
} | |
} | |
-(void)trashImage { | |
[self.currentItem trashImage]; | |
PhotoViewController *photoVC = (PhotoViewController*)_pageViewController.viewControllers[0]; | |
photoVC.imageView.image = nil; | |
} | |
-(IBAction)close:(id)sender { | |
[self.navigationController popViewControllerAnimated:YES]; | |
} | |
- (void)cameraController:(FastttCamera *)cameraController | |
didFinishCapturingImage:(FastttCapturedImage *)capturedImage | |
{ | |
// [self printSize:capturedImage.fullImage]; | |
} | |
- (void)cameraController:(FastttCamera *)cameraController | |
didFinishScalingCapturedImage:(FastttCapturedImage *)capturedImage | |
{ | |
/** | |
* Here, capturedImage.scaledImage contains the scaled-down version | |
* of the image. | |
*/ | |
// [self printSize:capturedImage.scaledImage]; | |
[self takeImage:capturedImage.scaledImage]; | |
} | |
-(void)printSize:(UIImage*)image { | |
NSUInteger s = CGImageGetHeight(image.CGImage) * CGImageGetBytesPerRow(image.CGImage); | |
NSLog(@"image size: %u",s); | |
} | |
-(void)takeImage:(UIImage*)image { | |
[self.currentItem saveImage:image]; | |
PhotoViewController *photoVC = (PhotoViewController*)_pageViewController.viewControllers[0]; | |
photoVC.imageView.image = image; | |
PhotoViewController *nextPhotoVC = [self viewControllerAtIndex:_currentItemIndex+1]; | |
if(nextPhotoVC) { | |
//scroll to next item | |
++_currentItemIndex; | |
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, 1 * NSEC_PER_SEC), dispatch_get_main_queue(), ^{ | |
// __weak CameraViewController *weakSelf = self; | |
// [_pageViewController setViewControllers:@[nextPhotoVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) { | |
// [weakSelf updateState]; | |
// weakSelf.taking = NO; | |
// }]; | |
[_pageViewController setViewControllers:@[nextPhotoVC] direction:UIPageViewControllerNavigationDirectionForward animated:YES completion:^(BOOL finished) { | |
[self updateState]; | |
}]; | |
}); | |
} else { | |
//taken your last picture, don't scroll | |
[self updateState]; | |
} | |
} | |
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation | |
{ | |
return (interfaceOrientation == UIInterfaceOrientationLandscapeLeft || interfaceOrientation == UIInterfaceOrientationLandscapeRight); | |
} | |
@end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment