Skip to content

Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

License

Notifications You must be signed in to change notification settings

theangelperalta/TGCameraViewController

 
 

Repository files navigation

TGCameraViewController

TGCameraViewController

Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

Build Status  License MIT  Cocoapods  Cocoapods  Analytics

  • Completely custom camera with AVFoundation, written in Swift 3.0.1
  • Custom view with camera permission denied
  • Custom button colors
  • Easy way to access album (camera roll)
  • Flash/Torch auto, off and on
  • Video support
  • Focus
  • Front and back camera
  • Grid view
  • Preview photo view with three filters (fast processing)
  • Visual effects like Instagram iOS app
  • iPhone, iPod and iPad supported

This library can be applied on devices running iOS 8.0+.



Who use it

Find out who uses TGCameraViewController and add your app to the list.



Installation with Carthage

Carthage is a decentralized dependency manager that builds your dependencies and provides you with binary frameworks.

You can install Carthage with Homebrew using the following command:

$ brew update
$ brew install carthage

To integrate TGCameraViewController into your Xcode project using Carthage, specify it in your Cartfile:

github "acort3255/TGCameraViewController"

Run carthage to build the framework and drag the built TGCameraViewController.framework into your Xcode project.



Usage

Take photo

#import "TGCameraViewController.h"

@interface TGViewController : UIViewController <TGCameraDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *photoView;

- (IBAction)takePhotoTapped;

@end



@implementation TGViewController

- (IBAction)takePhotoTapped
{
    TGCameraNavigationController *navigationController =
    [TGCameraNavigationController newWithCameraDelegate:self];

    [self presentViewController:navigationController animated:YES completion:nil];
}

#pragma mark - TGCameraDelegate optional

- (void)cameraWillTakePhoto
{
    NSLog(@"%s", __PRETTY_FUNCTION__);
}

- (void)cameraDidSavePhotoWithError:(NSError *)error
{
    NSLog(@"%s error: %@", __PRETTY_FUNCTION__, error);
}

#pragma mark - TGCameraDelegate required

- (void)cameraDidCancel
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)cameraDidTakePhoto:(UIImage *)image
{
    _photoView.image = image;
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)cameraDidSelectAlbumPhoto:(UIImage *)image
{
    _photoView.image = image;
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

Choose photo

#import "TGCameraViewController.h"
#import "TGCameraViewController-Swift.h"

@interface TGViewController : UIViewController
<UINavigationControllerDelegate, UIImagePickerControllerDelegate>

@property (strong, nonatomic) IBOutlet UIImageView *photoView;

- (IBAction)chooseExistingPhotoTapped;

@end



@implementation TGViewController

- (IBAction)chooseExistingPhotoTapped
{
    UIImagePickerController *pickerController =
    [TGAlbum imagePickerControllerWithDelegate:self];

    [self presentViewController:pickerController animated:YES completion:nil];
}

#pragma mark - UIImagePickerControllerDelegate

- (void)imagePickerController:(UIImagePickerController *)picker
didFinishPickingMediaWithInfo:(NSDictionary *)info
{
    _photoView.image = [TGAlbum imageWithMediaInfo:info];
    [self dismissViewControllerAnimated:YES completion:nil];
}

- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
    [self dismissViewControllerAnimated:YES completion:nil];
}

@end

Change colors

@implementation TGViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    
    UIColor *tintColor = [UIColor greenColor];
    [TGCameraColor setTintColor:tintColor];
}

@end

Options

Option Type Default Description
TGCamera.toggleButtonHidden BOOL (true/false)(YES/NO) (false/NO) Displays or hides the button that switches between the front and rear camera
TGCamera.albumButtonHidden BOOL (true/false)(YES/NO) (false/NO) Displays or hides the button that allows the user to select a photo from his/her album
TGCamera.filterButtonHidden BOOL (true/false)(YES/NO) (false/NO) Displays or hides the button that allows the user to filter his/her photo
TGCamera.saveMediaToAlbum BOOL (true/false)(YES/NO) (false/NO) Whether or not to save the media to the camera roll
#import "TGCamera.h"

@implementation UIViewController

- (void)viewDidLoad
{
    //...
    TGCamera.toggleButtonHidden = YES;
    TGCamera.albumButtonHidden = YES;
    TGCamera.filterButtonHidden = YES;
    TGCamera.saveMediaToAlbum = YES;
    TGCamera.stopWatchHidden = NO;
    TGCamera.maxDuration = CMTimeMake(10, 1);
    //...
}

- (IBAction)buttonTapped
{
    //...
    BOOL hiddenToggleButton = TGCamera.toggleButtonHidden;
    BOOL hiddenAlbumButton = TGCamera.albumButtonHidden;
    BOOL hiddenFilterButton = TGCamera.filterButtonHidden;
    BOOL saveToDevice = TGCamera.saveMediaToAlbum;
    BOOL stopWatchHidden = TGCamera.stopWatchHidden;
    //...    
}

@end


Requirements

TGCameraViewController works on iOS 8.0+ version and is compatible with ARC projects. It depends on the following Apple frameworks, which should already be included with most Xcode templates:

  • PHPhotoLibrary.framework
  • AVFoundation.framework
  • CoreImage.framework
  • Foundation.framework
  • MobileCoreServices.framework
  • UIKit.framework

You will need LLVM 3.0 or later in order to build TGCameraViewController.



Todo

  • Landscape mode support
  • Zoom
  • Image size as global parameter
  • Fast animations
  • Create a custom picker controller
  • Zoom does not work with the camera roll pictures


License

This code is distributed under the terms and conditions of the MIT license.



Change-log

A brief summary of each TGCameraViewController release can be found on the releases.

About

Custom camera with AVFoundation. Beautiful, light and easy to integrate with iOS projects.

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages

  • Swift 95.1%
  • Objective-C 4.9%