easier way to subview a UIImagePickerController? mines not working - ios

When I run my code and launch the camera with the code below I get my custom overlayView along with the default camera buttons. The only problem is, now, I get a blank black box where my UIImagePicker once was. I am simply trying to create a camera using the default UIImagePicker controls and buttons and then add my own IBOutlet UILabel over top of the default imagePickerController so that my label is displayed along with all the default camera controls. I'm having a terrible time accomplishing this though. cheers!
- (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = NO;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = self.imagePicker.cameraOverlayView.frame;
self.imagePicker.cameraOverlayView = self.overlayView;
self.overlayView = nil;
}
[self presentViewController:self.imagePicker animated:YES completion:nil];
}

Try to use my code. It worked fine. May be you achieve what you want. I created a controller, and used it's view to set cameraOverlayView property. I didn't use nib files, I created everything programmatically.
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.tabBarItem.image = [UIImage imageNamed:#"86-camera"];
self.cameraOverlayViewController = [[CameraOverlayViewController alloc] init];
self.cameraOverlayViewController.picker = picker;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = NO;
picker.toolbarHidden = YES;
picker.cameraOverlayView = self.cameraOverlayViewController.view;
picker.delegate = self.cameraOverlayViewController;
}
else if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeSavedPhotosAlbum]) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
}
This is a code for custom CameraOverlayViewController:
Interface file:
#import <UIKit/UIKit.h>
#interface CameraOverlayViewController : UIViewController <UIImagePickerControllerDelegate, UINavigationControllerDelegate>
#property (nonatomic, strong) UIImagePickerController *picker;
#end
Implementation file:
#import "CameraOverlayViewController.h"
#import "BButton.h"
#import "AnalyseViewController.h"
#import "Tree.h"
#interface CameraOverlayViewController ()
{
}
#end
#implementation CameraOverlayViewController
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
self.view.backgroundColor = [UIColor clearColor];
self.view.opaque = NO;
}
return self;
}
- (void)loadView
{
[super loadView];
UIView *bottomView = [[UIView alloc] initWithFrame:CGRectMake(0, self.view.bottom - 150, 320, 150)];
bottomView.backgroundColor = [UIColor blackColor];
BButton *button = [[BButton alloc] initWithFrame:CGRectMake(50, 25, 220, 50) type:BButtonTypePrimary];
[button setTitle:#"Сфотографировать" forState:UIControlStateNormal];
[button addTarget:self action:#selector(buttonClicked:) forControlEvents:UIControlEventTouchUpInside];
[bottomView addSubview:button];
[self.view addSubview:bottomView];
UIView *topView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 70)];
topView.backgroundColor = [UIColor clearColor];
UILabel *infoLabel = [[UILabel alloc] initWithFrame:CGRectMake(10, 5, 310, 60)];
infoLabel.backgroundColor = [UIColor clearColor];
infoLabel.font = [UIFont fontWithName:#"Georgia" size:18];
infoLabel.textColor = [UIColor whiteColor];
infoLabel.textAlignment = NSTextAlignmentCenter;
infoLabel.numberOfLines = 0;
infoLabel.text = #"Поместите лист дерева внутри рамки, чтобы\nсфотографировать его.";
[topView addSubview:infoLabel];
[self.view addSubview:topView];
UIView *bordersView = [[UIView alloc] initWithFrame:CGRectMake(10, topView.bottom + 10, 300, 300)];
bordersView.layer.cornerRadius = 10;
bordersView.layer.borderColor = [UIColor whiteColor].CGColor;
bordersView.layer.borderWidth = 2;
bordersView.backgroundColor = [UIColor clearColor];
[self.view addSubview:bordersView];
}
#pragma mark - UIImagePickerControllerDelegate
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
UIImage *image = [info valueForKey:UIImagePickerControllerOriginalImage];
AnalyseViewController *analyseViewController = [[AnalyseViewController alloc] initWithNibName:nil bundle:nil];
analyseViewController.baseImage = image;
analyseViewController.treesArray = [Tree retrieveAllTrees];
UINavigationController *analyseNavController = [[UINavigationController alloc] initWithRootViewController:analyseViewController];
[AppDel.tabBarController presentViewController:analyseNavController animated:YES completion:nil];
}
#pragma mark - Other methods
- (void)buttonClicked:(id)sender
{
[self.picker takePicture];
}
#end
Delete unneeded classes like BButton yourself.

fixed it with this. I did some research on CGPoints & CGRect and come up with this solution. Not sure if it is the most elegant solution but it works and seems to make pretty good sense. - (void)viewDidLoad
{
[super viewDidLoad];
if (self.image == nil && [self.videoFilePath length] == 0) {
self.imagePicker = [[UIImagePickerController alloc] init];
self.imagePicker.delegate = self;
self.imagePicker.allowsEditing = YES;
self.imagePicker.videoMaximumDuration = 10;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) {
self.imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
self.imagePicker.mediaTypes = [UIImagePickerController availableMediaTypesForSourceType:self.imagePicker.sourceType];
[self presentViewController:self.imagePicker animated:NO completion:nil];
}
[[NSBundle mainBundle] loadNibNamed:#"OverlayView" owner:self options:nil];
self.overlayView.frame = CGRectMake(160,0,0,0);
self.imagePicker.cameraOverlayView = self.overlayView;
}

Related

how to change color of status bar of imagepickercontroller ios?

I need something like this status bar image but i am getting the status hidden but still i can not change the color. I am getting this status bar withour color
This is what i am doing.
-
(void)showGallery
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
// picker.navigationBarHidden = YES;
// picker.toolbarHidden = YES;
picker.navigationController.navigationBar.barTintColor=[UIColor orangeColor];
picker.navigationBar.backgroundColor = [UIColor orangeColor];
picker.navigationBar.barStyle=UIBarStyleBlack;
[ picker.navigationBar setTitleTextAttributes:#{NSForegroundColorAttributeName: [UIColor whiteColor]}];
[self presentViewController:picker animated:YES completion:NULL];
}
Use three steps:
1: Add UINavigationControllerDelegate, UIImagePickerControllerDelegate to your #interface yourController ()<>
2:
imagePickerController.delegate = self;
3:
-(void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
[[UIApplication sharedApplication] setStatusBarStyle:UIStatusBarStyleLightContent];
}
Try This:-
1.Create a view with height 20 points and change the background color to attach the viewcontrollerView (OR) change the background colour of your view controller follow like
UIView*statusbarview = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 20)];
statusbarview.backgroundColor = [UIColor greenColor];
[self.view addSubview:statusbarview];
(OR)
self.view.backgroundColor = [UIColor redColor];
This solved my problem.
-(void)showGallery
{
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.allowsEditing = NO;
picker.modalPresentationStyle = UIModalPresentationFullScreen;
picker.navigationBar.translucent = NO;
picker.navigationBar.barTintColor = [UIColor orangeColor];
picker.navigationBar.tintColor = [UIColor whiteColor];
picker.navigationBar.titleTextAttributes = #{NSForegroundColorAttributeName: [UIColor whiteColor]};
[self presentViewController:picker animated:YES completion:nil];
}

change text color of UIBarButtonItem in UIImagePickerController?

I use native UIImagePickerController in of my view controller.
I use a different color for UIBarButtonItem than what iPhone uses UIImagePickerController
is it possible for me to change textColor of UIImagePickerController.UIBarButtonItem ??
I tried
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
picker.navigationItem.rightBarButtonItem.tintColor = [UIColor redColor];
for (UIBarButtonItem *item in picker.navigationItem.rightBarButtonItems) {
item.tintColor = [UIColor redColor];
}
for (UIView *view in picker.navigationBar.subviews) {
NSLog(#"%#", [[view class] description]);
if ([[[view class] description] isEqualToString:#"UIBarButtonItem"]) {
[(UIBarButtonItem *)view setTintColor:[UIColor redColor]];
}
}
[self presentViewController:picker animated:YES completion:NULL];
Output of NSlog was
_UINavigationBarBackground
_UINavigationBarBackIndicatorView
EDIT 2:
I needed to do
picker.navigationBar.tintColor = [UIColor redColor];

What is wrong with my camera overlay iOS 7?

Whenever I run my app on a device and I choose to take a picture it crashes without warning can someone tell me what is wrong with my overlay?
CameraOverlay.h does not contain anything besides making UIView the superclass.
CameraOverlay.m
#implementation CameraOverlay
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
// load an image to show in the overlay
UIImage *constraints = [UIImage imageNamed:#"camera_overlay"];
UIImageView *constraintView = [[UIImageView alloc]initWithImage:constraints];
constraintView.frame = CGRectMake(30, 100, 260, 200);
[self addSubview:constraintView];
}
return self;
}
/*
// Only override drawRect: if you perform custom drawing.
// An empty implementation adversely affects performance during animation.
- (void)drawRect:(CGRect)rect
{
// Drawing code
}
*/
#end
viewController.m
- (IBAction)scanButton:(UIButton *)sender
{
CGRect screenRect = [[UIScreen mainScreen]bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.cameraOverlayView = overlay;
picker.delegate = self;
picker.allowsEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentViewController:picker animated:YES completion:NULL];
}
I found out what was wrong, I was setting the overlay of the camera before I set the source to the camera.
Updated code from the ViewController
- (IBAction)scanButton:(UIButton *)sender
{
CGRect screenRect = [[UIScreen mainScreen]bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
CameraOverlay *overlay = [[CameraOverlay alloc]initWithFrame:CGRectMake(0, 0, screenWidth, screenHeight)];
UIImagePickerController *picker = [[UIImagePickerController alloc]init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.cameraOverlayView = overlay;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentViewController:picker animated:YES completion:NULL];
}

UIPopoverController for iPad "must not be called with `nil`" error

I am trying to make an iPhone app work in an iPad but the UIPopoverController is
comming back with error.
- (IBAction)photoTapped1 {
if(UI_USER_INTERFACE_IDIOM()== UIUserInterfaceIdiomPhone){
// If in editing state, then display an image picker; if not, create and push a photo view controller.
if (self.editing) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
[self presentViewController:imagePicker animated:YES completion:nil];
[imagePicker release];
} else {
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}
}else{
if (self.editing){
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
self.popover.delegate =self;
[popover release];
}else{
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
recipePhotoViewController.hidesBottomBarWhenPushed = YES;
recipePhotoViewController.recipe = recipe;
[self.navigationController pushViewController:recipePhotoViewController animated:YES];
[recipePhotoViewController release];
}}}
The error I am getting is:
'NSInvalidArgumentException', reason: '-[UIPopoverController initWithContentViewController:] must not be called with nil.'
Anyone available to give me a hand on this code, I have looked on the internet for solutions and samples but can not seem to make it work.
Thank you.
___ added to original question_____
I am adding the recipePhotoViewController here, I am assuming that ImageView manipulation is the same for iPhone and iPad.
my.h File
#class Recipe;
#interface RecipePhotoViewController : UIViewController {
#private
Recipe *recipe;
UIImageView *imageView;
}
#property(nonatomic, retain) Recipe *recipe;
#property(nonatomic, retain) UIImageView *imageView;
#end
Here is my .m file
#implementation RecipePhotoViewController
#synthesize recipe;
#synthesize imageView;
- (void)loadView {
self.title = #"Photo";
imageView = [[UIImageView alloc] initWithFrame:[UIScreen mainScreen].applicationFrame];
imageView.autoresizingMask = UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleWidth;
imageView.contentMode = UIViewContentModeScaleAspectFit;
imageView.backgroundColor = [UIColor blackColor];
self.view = imageView; }
- (void)viewWillAppear:(BOOL)animated {
imageView.image = [recipe.image valueForKey:#"image"];}
- (BOOL)shouldAutorotateToInterfaceOrientation: (UIInterfaceOrientation)interfaceOrientation {
return (interfaceOrientation != UIInterfaceOrientationPortraitUpsideDown);
}
- (void)dealloc {
[imageView release];
[recipe release];
[super dealloc];
} #end
You are initializing the popover controller in a wrong way:
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
You should pass the controller you would like to display inside of the popover -- not the popover itself (which is nil since you have not yet initialised it)!
Maybe this would do it for you?
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
If this is correct, then you should also present the pop over you have just created: – presentPopoverFromRect:inView:permittedArrowDirections:animated:
-- e.g.:
[self.popover presentPopoverFromRect:sender.frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
where sender is the argument to :
- (IBAction)photoTapped1:(id)sender {
The content of your popover which you store in the variable popover is obviously nil. I can't see it ever being created in the code you provided.
Maybe you intended to present the Recipe photo controller as the content of the popover. In that case you would do something like
RecipePhotoViewController *recipePhotoViewController = [[RecipePhotoViewController alloc] init];
self.popover = [[UIPopoverController alloc] initWithContentViewController:recipePhotoViewController];
problem is in this line of your code ,
self.popover = [[UIPopoverController alloc] initWithContentViewController:popover];
try like this
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 400, 320, 260)];
popoverContent.view = popoverView;
//Add what ever you want popoverView
self.popover = [[UIPopoverController alloc] initWithContentViewController:popoverContent];
self.popover.delegate =self;

BarButtonItem With Popovercontroller?

I have a BarButtonItem and a Popovercontroller. the question is who can i pop something when i click on the button can some one help me. i will post some code what i have on this moment.
-(void) showPop:(id)sender{
NSLog(#"test");
UIPopoverController *pop = [[UIPopoverController alloc] initWithContentViewController:popover];
[pop setDelegate:self];
[pop presentPopoverFromBarButtonItem:button permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
}
- (id)initWithNibName:(NSString *)nibNameOrNil bundle:(NSBundle *)nibBundleOrNil
{
self = [super initWithNibName:nibNameOrNil bundle:nibBundleOrNil];
if (self) {
//self.title = NSLocalizedString(#"Nieuws", #"Nieuws");
/*if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
self.clearsSelectionOnViewWillAppear = NO;
self.contentSizeForViewInPopover = CGSizeMake(320.0, 600.0);
}*/
}
return self;
}
- (void)viewDidLoad
{
[super viewDidLoad];
_loading = NO;
self.title = #"Agenda";
if (_refreshHeaderView == nil) {
EGORefreshTableHeaderView *view = [[EGORefreshTableHeaderView alloc] initWithFrame:CGRectMake(0.0f, 0.0f - self.tableView.bounds.size.height, self.view.frame.size.width, self.tableView.bounds.size.height)];
view.delegate = self;
[self.tableView addSubview:view];
_refreshHeaderView = view;
}
// update the last update date
self.navigationController.navigationBar.tintColor = [UIColor darkGrayColor];
if ([self.navigationController.navigationBar respondsToSelector:#selector( setBackgroundImage:forBarMetrics:)]){
[self.navigationController.navigationBar setBackgroundImage:[UIImage imageNamed:#"Bar-bg.png"] forBarMetrics:UIBarMetricsDefault];
}
[_refreshHeaderView refreshLastUpdatedDate];
self.tableView.contentInset = UIEdgeInsetsMake(66.0f, 0.0f, 0.0f, 0.0f);
[_refreshHeaderView egoRefreshScrollViewDidEndDragging: self.tableView];
//[self loadData];
//[popButton addTarget:self action:#selector(showPop:) forControlEvents:UIControlEventTouchUpInside];
button = [[UIBarButtonItem alloc] initWithTitle:#"Filter" style:UIBarButtonItemStyleBordered target:self action:#selector(showPop)];
self.navigationItem.leftBarButtonItem = button;
}
Might just be a typo but when you create your button, the selector should be showPop: (with a colon) not showPop.

Resources