ZBar remove info button (ios 6) - ios

How to I remove the information button from the toolbar at the bottom screen (reader screen).I have tried the using the overlay method but it didn't work. Hope someone would save me. Thanks
-(void)viewDidLoad
{
[super viewDidLoad];
// Do any additional setup after loading the view.
ZBarReaderController *reader = [ZBarReaderController new];
reader.readerDelegate =self;
reader.sourceType =UIImagePickerControllerSourceTypeCamera;
reader.showsCameraControls=YES;
// Define button title color when disabled (Grey)
[btnFindMe setTitleColor:[UIColor grayColor] forState:UIControlStateDisabled];
[self activateScan];
}
-(void) activateScan
{
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
[reader.scanner setSymbology: 0
config: ZBAR_CFG_ENABLE
to: 0];
[reader.scanner setSymbology: ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 1];
reader.readerView.zoom = 1;
reader.showsZBarControls=FALSE;
UIView *overlay = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,480.0)];
overlay.backgroundColor = [UIColor clearColor];
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0.0,510.0,320.0,54.0)];
UIBarButtonItem *cancelButton = [[UIBarButtonItem alloc]
initWithBarButtonSystemItem:UIBarButtonSystemItemCancel
target:self action:#selector(closeScanner)];
toolbar.items = [NSArray arrayWithObjects:cancelButton,nil];
[overlay addSubview:toolbar];
reader.cameraOverlayView = overlay;
[self presentModalViewController: reader animated: YES];
}

I ended up creating new UIView & apply it to cameraOverlayView property of ZBarReaderViewController's object codeReader.
It's actually recommended from ZBar official docs.
self.codeReader.showsCameraControls = NO;
self.codeReader.showsZBarControls = NO;
[self.codeReader setCameraOverlayView:self.viewCancelButtonQRCodeReader];
[Here's the screenshot of UIView that i added. It has background color as clearColor.]

Related

xCode Creating UIImagePickerController and Referencing It

for my app I want to create a custom camera overlay and create a UIImagePickerController to start recording video. (below)
- (IBAction)RecordVideo:(UIButton *)sender {
//initialise camera view
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
cameraUI.showsCameraControls = NO;
cameraUI.navigationBarHidden = YES;
cameraUI.toolbarHidden = YES;
OverlayView *overlay = [[OverlayView alloc]
initWithFrame:CGRectMake(0, 0, 20,20)];
cameraUI.cameraOverlayView = overlay;
[self presentViewController:cameraUI animated:YES completion:nil];
}
as part of the cameraOverlayView I've instantiated a UIButton:
- (id)initWithFrame:(CGRect)frame {
if (self = [super initWithFrame:frame]) {
//clear the background color of the overlay
self.opaque = NO;
self.backgroundColor = [UIColor clearColor];
... some overlay UI stuff
UIButton *captureBtn = [UIButton buttonWithType:UIButtonTypeRoundedRect];
UIImage *captureBtnImg = [UIImage imageNamed:#"captureBtn.png"];
[captureBtn setBackgroundImage:captureBtnImg forState:UIControlStateNormal];
captureBtn.frame = CGRectMake(self.frame.size.width/2 - 15,
430,
80,
80);
[self addSubview:captureBtn];
}
return self;
}
So how do I create an IBAction for this button which can then make the UIImagePickerController cameraUI start recording?
If somebody could also explain to me how the IBActions are called from specific buttons only that would also be amazing because that seems like black magic to me?
You can add target like this,
[captureBtn addTarget:self action:#selector(captureBtnclick:) forControlEvents:UIControlEventTouchUpInside];
and you action method shoulbe like this
-(void)captureBtnclick :(UIButton*)sender{
//handle your task on click here
}
second thing why you are adding layer on it? you can use default video recording from imagePicker by setting mediatype like
cameraUI.mediaTypes = [[NSArray alloc] initWithObjects: (NSString *) kUTTypeMovie, nil];
Update accroding to comment
you can use on button click,
[picker startVideoCapture]; //in your case cameraUI i think
Update 2 :
in your .h file,
#property UIImagePickerController *cameraUI;
then in your method RecordVideo use like,
self.cameraUI = [[UIImagePickerController alloc] init];
self.cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
//etc.....
By this way you can use camaraUI in whole class by self
hope this will help :)

UIBarButtonItem doesn't appear

I have an issue, when the view is loaded, it will load the UIBarButtonItem, but then i have to set it to nil in "mostra_filtro_btn", but then again in "load_map" i have to set it, but it doesn't show up.
Here is my code:
//
// FirstViewController.m
// House Finder
//
// Created by Giovanni Poli on 12/05/15.
// Copyright (c) 2015 Giovanni Poli. All rights reserved.
//
#import "MapViewController.h"
#import <QuartzCore/QuartzCore.h>
#import "Reachability.h"
#import "UIKit/UIKit.h"
#import <Foundation/Foundation.h>
#import "FiltroViewController.h"
#interface MapViewController ()
#end
#implementation MapViewController
#synthesize filtro_controller,overlay_filtro_counter,mappa_controller;
-(void)load_map{
NSLog(#"load_map");
[mapView removeFromSuperview];
[mappa_controller.view removeFromSuperview];
[filtro_controller.view removeFromSuperview];
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
}
- (id) init{
filtro_controller = [[FiltroViewController alloc]init];
[self.view addSubview:filtro_controller.view];
[self addChildViewController:filtro_controller];
return self;
}
- (void)viewDidLoad {
self.title = #"Mappa";
self.navigationItem.title = #"House Finder";
self.navigationController.navigationBar.translucent = FALSE;
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
NSString *filePath = [[NSBundle mainBundle] pathForResource:#"data" ofType:#"json"];
NSData *content = [[NSData alloc] initWithContentsOfFile:filePath];
NSDictionary *json = [NSJSONSerialization JSONObjectWithData:content options:kNilOptions error:nil];
NSArray * json_all = [json objectForKey:#"results"];
mapView = [[MKMapView alloc]initWithFrame:CGRectMake(0,0,self.view.frame.size.width,self.view.frame.size.height-40)];
mapView.delegate = self;
mapView.showsUserLocation = NO;
mapView.userInteractionEnabled = YES;
CLLocationCoordinate2D annotationCoord;
self.view.userInteractionEnabled = YES;
NSDictionary * temp;
for (id object in json_all) {
temp = object[#"titolo"];
annotationCoord.latitude = [object[#"lat"] floatValue];
annotationCoord.longitude = [object[#"lon"] floatValue];
MKPointAnnotation *annotationPoint = [[MKPointAnnotation alloc] init];
annotationPoint.coordinate = annotationCoord;
annotationPoint.title = object[#"titolo"];
annotationPoint.subtitle = object[#"agenzia"];
[mapView addAnnotation:annotationPoint];
}
[mapView showAnnotations:[mapView annotations] animated:YES];
[self.view addSubview:mapView];
[self.view setNeedsDisplay];
}
- (IBAction) mostra_filtro_btn: (id)sender{
NSLog(#"mostra_filtro_btn");
self.navigationItem.rightBarButtonItem = nil;
filtro_controller = [[FiltroViewController alloc]init];
[self.view addSubview:filtro_controller.view];
[self addChildViewController:filtro_controller];
}
- (MKAnnotationView *)mapView:(MKMapView *)mapViews viewForAnnotation:annotation{
if (annotation == mapViews.userLocation) return nil;
MKPointAnnotation * temp = annotation;
MKAnnotationView * m = [[MKAnnotationView alloc] initWithAnnotation:annotation reuseIdentifier:#"casa"];
m.canShowCallout = YES;
m.enabled = YES;
m.userInteractionEnabled = YES;
NSString * icon_file = [NSString stringWithFormat:#"%#.png",temp.subtitle];
m.image = [UIImage imageNamed:icon_file];
return m;
}
- (void)mapView:(MKMapView *)mapView didSelectAnnotationView:(MKAnnotationView *)view{
NSLog(#"overlay prezzo");
}
- (void)didReceiveMemoryWarning {
[super didReceiveMemoryWarning];
}
#end
Use the following code to nil the navigation item so it will hide where ever you want
[self.navItem setRightBarButtonItem:nil];
[self.navItem setLeftBarButtonItem:nil];
Try first create the UIButton then put it into the navigation button as follow
UIButton *backButton = [[UIButton alloc] initWithFrame: CGRectMake(0, 0, 44.0f, 30.0f)];
[backButton setImage:[UIImage imageNamed:#"back.png"] forState:UIControlStateNormal];
[backButton addTarget:self action:#selector(popVC) forControlEvents:UIControlEventTouchUpInside];
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithCustomView:backButton];
Since I can't post this as a comment here is what I think is missing inside load_map:
dispatch_async(dispatch_get_main_queue(), ^{
NSLog(#"load_map");
[mapView removeFromSuperview];
[mappa_controller.view removeFromSuperview];
[filtro_controller.view removeFromSuperview];
UIBarButtonItem *Button = [[UIBarButtonItem alloc] initWithTitle:#"Filtro" style:UIBarButtonItemStyleBordered target:self action:#selector(mostra_filtro_btn:)];
[Button setTitle:#"Filtro"];
[Button setTitleTextAttributes:[NSDictionary dictionaryWithObjectsAndKeys:[UIColor whiteColor], NSForegroundColorAttributeName,nil]forState:UIControlStateNormal];
self.navigationItem.rightBarButtonItem = Button;
})
This is a possible solution till you try it. If you share the code from where you call load_map it would be great!
Cheers!
Your code works perfect, as you said you are adding button with method mostra_filtro_btn : in viewDidLoad method, and on click of button, button from navigation bar set to nil.
But the problem is that, from nowhere you calls load_map method. You need to call this method once the button gets nil, to get it back with load_map method.
May you get it.
Enjoy Coding!!

Change items in navigation bar on device rotation

I have custom UIBarButton items added to UINavigationBar as rightbarbuttonitems. I add two more items in UIBarButton when device goes to landscape mode. I am getting rotation call and I am correctly removing items from UIBarbuttons array based on device orientation, but my navigationbar item set never gets updates.
If i start with portrait mode, it shows what it suppose to. When I rotate to landscape new items are not added to navigation bar and vice versa extra item won't go when device go to portrait.
I am not sure how I can change navigationbaritems on device rotation. Per me I am doing all things correct.
-(void)setUpOnRotation:(BOOL)toPortrait{
_searchMessage = [[UILabel alloc] initWithFrame:CGRectMake(3.0, 0, 110, 20)];
_searchMessage.numberOfLines = 2;
_searchMessage.textColor = [UIColor blackColor];
_searchMessage.font = [UIFont systemFontOfSize:8.0];
_searchMessage.text = #"";
_searchBar = [[UISearchBar alloc] initWithFrame:CGRectMake(0, 15, 130, 25)];
_searchBar.delegate = self;
_searchBar.showsCancelButton = NO;
UIBarButtonItem* doneButton = [BarButtons doneButtonWithTarget:self action:#selector(cancel)];
UIBarButtonItem *searchActivityItem = [[UIBarButtonItem alloc] initWithCustomView:_searchMessage];
UIBarButtonItem *searchItem = [[UIBarButtonItem alloc] initWithCustomView:_searchBar];
UIBarButtonItem *in = [BarButtons nativeButtonNamed:#"In"
title:#"In"
target:self
action:#selector(In)];
UIBarButtonItem *out = [BarButtons nativeButtonNamed:#"Out"
title:#"Out"
target:self
action:#selector(Out)];
NSMutableArray *itemsSet;
itemsSet = [NSMutableArray arrayWithObjects:in,
out,
searchItem,
searchActivityItem,
doneButton, nil];
if (toPortrait) {
if ([itemsSet containsObject:searchItem] || [itemsSet containsObject:searchActivityItem]) {
[itemsSet removeObject:searchActivityItem];
[itemsSet removeObject:searchItem];
}
}
[_searchBar release];
[searchItem release];
[_searchActivity release];
[_searchMessage release];
[searchActivityView release];
self.navigationItem.rightBarButtonItems = itemsSet;
}
- (void)willAnimateRotationToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation duration:(NSTimeInterval)duration
{
[self setUpOnRotation:UIInterfaceOrientationIsPortrait(toInterfaceOrientation)];
} -(void)viewWillAppear:(BOOL)animated{
[super viewWillAppear:animated];
[self.navigationController setNavigationBarHidden:NO animated:animated];
[self setUpOnRotation:UIInterfaceOrientationIsPortrait(self.interfaceOrientation)];}
Note: setUpOnRotaion method is called from willAnimateRotationToInterfaceOrientation and viewWillAppear with UIInterfaceOrientationIsPortrait(self.intefaceOrientation) and it does give me correct result. I have debugged.
In willAnimateRotationToInterfaceOrientation change cehck for orientation
if([uidevice orientaiton]statusbarorientation]){
self.naviogationite.rightbarbuttonitems = #[btn1,btn2,btn3];
}
else{
self.naviogationite.rightbarbuttonitems = #[abtn1,abtn2,abnt3];
}
u can do like this
can u do like this
NSMutableArray *itemsSet;
if(!toPortrait){
itemsSet = [NSMutableArray arrayWithObjects:in,
out,
searchItem,
searchActivityItem,
doneButton, nil];
}
if (toPortrait) {
itemsSet = [NSMutableArray arrayWithObjects:in,
out,
doneButton, nil];
}

Adding UINavigation bar programmatically

I was trying to add the navigation bar to the application programmatically but I didn't got any success.
I had tried the code mentioned below
UIBarButtonItem *alefttbarButton = [[UIBarButtonItem alloc] initWithTitle:#"Setting" style:UIBarButtonItemStyleBordered target:self action:#selector(settingAction:)];
alefttbarButton.style = UIBarButtonItemStyleBordered;
alefttbarButton.tintColor= [UIColor redColor];
self.navigationItem.leftBarButtonItem=alefttbarButton;
self.navigationController.delegate=self;
self.title =#"test";
Here's how I did it. In this particular case I created my views all by hand. Starting in the applicationDidFinishLaunching, I have the following code:
UIWindow *window = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
mainCtl = [[MainController alloc] init];
[window addSubview:mainCtl.nav.view];
[window makeKeyAndVisible];
As you can see I here allocate and initialize an instance of MainController, which is a subclass of UIViewController.
Then, in the initialization of this MainController I have a call to the navigation bar initialization code:
[self initNavBar];
which is the following function:
- (void) initNavBar
{
printf("initNavBar entered\n");
self.nav = [[UINavigationController alloc] initWithRootViewController: self];
//setup the middle view
int btnCount = 4;
CGRect buttonsFrame = CGRectMake(0, 0, btnCount*BUTTONWIDTH + (btnCount-1)*BUTTONSPACING + 2*BUTTONMARGIN, BUTTONHEIGHT + 2*BUTTONMARGIN);
UIView *buttonsView = [[UIView alloc] initWithFrame:buttonsFrame];
UIButton *button;
CGFloat left = BUTTONMARGIN;
// create button for photo selector invocation
button = [self buttonWithName:#"photo" target:self selector:#selector(showImagePicker) left:left];
//button = [self createButton:#"photo" action:#selector(showImagePicker) left:left];
[buttonsView addSubview:button];
left += (BUTTONWIDTH+BUTTONSPACING);
button = [self buttonWithName:#"crop" target:self selector:#selector(cropImage) left:left];
[buttonsView addSubview: button];
left += (BUTTONWIDTH+BUTTONSPACING);
kissButton = [self buttonWithName:#"kiss" target:self selector:#selector(cropImage) left:left];
[buttonsView addSubview: kissButton];
//left += (BUTTONWIDTH+BUTTONSPACING);
left += (BUTTONWIDTH+BUTTONSPACING);
button = [self buttonWithName:#"mail" target:self selector:#selector(showMailDialog) left:left];
//button = [self createButton:#"mail" action:#selector(showMailDialog) left:left];
[buttonsView addSubview:button];
Class mailClass = (NSClassFromString(#"MFMailComposeViewController"));
//only enable the mail button if the class exists
button.enabled = (mailClass != nil);
printf("initNavBar done\n");
}
This is all working code. If you can look through the cruft you'll manage to get the picture.
Hope this helps.

iOS 7 UITableView inside a popover

I have a UITableView which has some custom styling. This table view appears in two places in the app, one of which is inside a UIPopoverController. However when the tableview is inside the popover it takes on the default tableview styling as stated in the UI Transition Guide under "Popover".
The problem I have is that there appears to be nowhere to change this behaviour. Regardless of where I try and modify properties of the tableview the view inside the popover doesn't change.
Anyone dealt with this issue before or have any ideas?
Here is the init method of LibraryProductView where I create the table view:
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
self.sectionOrdering = [NSArray arrayWithObjects:
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DESCRIPTION],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_DOCUMENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_ACTIVE_INGREDIENTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_PRODUCTS],
[NSNumber numberWithInt:LIBRARY_PRODUCT_SECTION_RELATED_DOCUMENTS], nil];
self.backgroundColor = [UIColor whiteColor];
self.tableView = [[UITableView alloc] initWithFrame:CGRectInset(self.bounds, 10, 0) style:UITableViewStyleGrouped];
self.tableView.backgroundColor = [UIColor whiteColor];
self.tableView.dataSource = self;
self.tableView.delegate = self;
self.tableView.separatorColor = [UIColor clearColor];
self.tableView.showsVerticalScrollIndicator = NO;
[self addSubview:self.tableView];
}
return self;
}
Here is where the containing view (LibraryProductView) is added to the popover:
- (IBAction)didTouchInformationButton:(id)sender
{
if (_infoPopover != nil && _infoPopover.isPopoverVisible)
{
[_infoPopover dismissPopoverAnimated:YES];
return;
}
CGSize preferredSize = CGSizeMake(600.0f, 500.0f);
LibraryProductViewController* productController = [[[LibraryProductViewController alloc] initWithPreferredSize:preferredSize] autorelease];
productController.filterByMyCompany = NO;
productController.product = _activityInput.product;
UINavigationController* nav = [[[UINavigationController alloc] initWithRootViewController:productController] autorelease];
nav.title = _activityInput.product.name;
RELEASE(_infoPopover);
_infoPopover = [[UIPopoverController alloc] initWithContentViewController:nav];
_infoPopover.popoverContentSize = CGSizeMake(preferredSize.width, preferredSize.height + 46);
[_infoPopover presentPopoverFromRect:_infoButton.frame inView:_infoButton permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];
}
The LibraryProductView is created within viewDidLoad method of LibraryProductViewController.
- (void)viewDidLoad
{
[super viewDidLoad];
self.libraryProductView = [[LibraryProductView alloc] initWithFrame:(usingPreferredSize ? CGRectMake(0.0, 0.0, preferredSize.width, preferredSize.height) : self.view.bounds)];
self.libraryProductView.dataSource = self;
self.libraryProductView.delegate = self;
[self.view addSubview:self.libraryProductView];
}
To set properties for the TableView you might do so in
- (NSInteger) numberOfSectionsInTableView:(UITableView *)tableView
{
[tableView setBackgroundColor:[UIColor redcolor]];
[tableView setSeparatorColor: [UIColor blueColor]];
return 1;
}
This, of course, assumes you have set UITableViewDataSource in your .h file

Resources