I've following code running on iPad, I'm usin Zbar 1.2.2 beta version for support in iPad.
ZBarReaderViewController* mReader = [[ZBarReaderViewController alloc] init];
mReader.readerDelegate = self;
mReader.showsZBarControls = NO;
mReader.wantsFullScreenLayout = NO;
mReader.readerView.frame = CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height);
UIButton *imageView = [[UIButton alloc] init];
imageView.frame = CGRectMake(0, 0, UIScreen.mainScreen.bounds.size.width, UIScreen.mainScreen.bounds.size.height);
[self setupToolBar:imageView];
mReader.cameraOverlayView = imageView;
setupToolBar does following
- (void)setupToolBar:(UIButton*)imageView
{
[imageView retain];
UIToolbar* imagePickerToolBar = [[UIToolbar alloc] init];
UIImage *c = [UIImage imageNamed:#"close.png"];
UIBarButtonItem *closeItem = [[UIBarButtonItem alloc] initWithImage:c style:UIBarButtonItemStylePlain target:self action:#selector(closeBarItemPressed:)];
NSArray *items = [NSArray arrayWithObjects: closeItem, nil];
[imagePickerToolBar setItems:items animated:NO];
imagePickerToolBar.frame = CGRectMake(0, UIScreen.mainScreen.bounds.size.height - imagePickerToolBar.frame.size.height, imagePickerToolBar.frame.size.width, imagePickerToolBar.frame.size.height);
[imageView addSubview:imagePickerToolBar];
[imageView bringSubviewToFront:imagePickerToolBar];
[imagePickerToolBar release];
[closeItem release];
[imageView release];
}
Now my question : closeBarItemPressed: is not getting called, why and how to fix it ?
I had this problem too. It looks like touches are ignored in the bottom part of the overlay view. Try moving the button a little bit higher and it will work. (in your case if you change toolbar frame to be in the top of the screen, I bet your method will be called, at least this is what happened to me). Not sure why this is happening though.
Basically I solved my problem, by recompiling Zbar, with modified iPad settings. Now it works OK.
Related
I am attempting to set a label into a subclassed UIToolBar. I am first creating the label, then converting it to a UIBarButtonItem and setting them to the toolbar, but the toolbar just appears blank.
here is my code in my init method of my subclassed toolbar
NSMutableArray *items = [[NSMutableArray alloc] init];
// prep the total label
_totalLabel = [[UILabel alloc] init];
_totalLabel.font = [_totalLabel.font fontWithSize:15];
_totalLabel.textColor = [UIColor whiteColor];
_totalLabel.text = NSLocalizedString(#"TOTAL", nil);
_totalLabel.frame = CGRectMake(0, 0, 100, 44);
_totalLabel.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight | UIViewAutoresizingFlexibleTopMargin;
_totalLabel.layer.borderWidth = 2;
_totalLabel.layer.borderColor = [UIColor greenColor].CGColor;
_totalLabel.backgroundColor = [UIColor clearColor];
UIBarButtonItem *spacer2 = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace target:nil action:nil];
[items addObject:spacer2];
UIBarButtonItem *total = [[UIBarButtonItem alloc] initWithCustomView:_totalLabel];
[items addObject:total];
[self setItems:items];
any idea whats wrong?
Where are you calling this code from? If you have it in initWithFrame: or initWithCoder: it will not work.
Try this:
- (void)layoutSubviews {
[super layoutSubviews];
if(self.items.count == 0) {
//Your code here
}
}
That will get it working. The question is though should you be doing this in layoutSubviews? Probably not. You could also put a setup method on your UIToolbar and call that at a later point in your application.
This is not a uitoolbar. this is a navigation bar so please remove navigationbar and add toolbar . Try this type .
This looks like a bug to me, but maybe someone can think of a workaround?
Basically if you have a custom UIToolbar, its button items will automatically hide when you present a UIActivityViewController, and reappear when you dismiss it. This is only the case on the iPhone. Being that UIActivityViewController doesn't hide the entire screen it just looks weird that buttons disappear behind the dimmed screen.
To replicate, simply start a single view project and use the following code on the view controller:
- (void)viewDidLoad {
UIToolbar *toolbar = [[UIToolbar alloc] initWithFrame:CGRectMake(0, 0, self.view.bounds.size.width, 40)];
UIBarButtonItem *button = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemAction target:self action:#selector(didTapAction)];
toolbar.items = [NSArray arrayWithObject:button];
[self.view addSubview:toolbar];
}
- (void)didTapAction {
NSArray *items = [NSArray arrayWithObjects:#"Text", nil];
UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
[self presentViewController:sharing animated:YES completion:nil];
}
Found a workaround. Simply get rid of all the items before presenting, and add them back right after.
- (void)didTapAction {
NSArray *items = [NSArray arrayWithObjects:#"Text", nil];
UIActivityViewController *sharing = [[UIActivityViewController alloc] initWithActivityItems:items applicationActivities:nil];
NSArray *barItems = toolbar.items;
toolbar.items = nil;
[self.navigationController presentViewController:sharing animated:YES completion:nil];
toolbar.items = barItems;
}
know it is quite old thread for but those who look this page for solution, here you go :
With iOS7, you can use this approach to show/hide your toolbar button :
if(// your code Condition)
{ self.toolbarBtn1.enabled = YES;
self.toolbarBtn1.tintColor = nil; }
else
{ self.toolbarBtn1.enabled = NO;
self.toolbarBtn1.tintColor = [UIColor clearColor]; }
I have installed 4.2 iphone sdk today and ran my project (which is written in 4.0) with 4.2. I noticed that toolbar items are misplaced over toolbar, both in ipad, iphone simulators. Is there anyone else other than me who has encountered with this? Here is the code:
#define TOOLBAR_HEIGHT 34
#define TOOLBAR_ITEM_WIDTH 90
// extends UIView
#implementation MapViewControllerContainer
- (void) setFrame:(CGRect)frame
{
[super setFrame:frame];
if (self.subviews.count == 2)
{
((UIView *)[self.subviews objectAtIndex:0]).frame = CGRectMake(0, 0, frame.size.width, TOOLBAR_HEIGHT);
((UIView *)[self.subviews objectAtIndex:1]).frame = CGRectMake(0, TOOLBAR_HEIGHT, frame.size.width,
frame.size.height - TOOLBAR_HEIGHT);
}
}
#end
// extends UIViewController
#implementation MapViewController
- (void) loadView
{
self.view = [[MapViewControllerContainer alloc] init];
[self.view release];
UIToolbar * toolbar = [[UIToolbar alloc] init];
toolbar.barStyle = UIBarStyleBlack;
UIBarButtonItem * flexibleItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemFlexibleSpace
target:nil action:nil];
detailsButton = [[UIBarButtonItem alloc] initWithTitle:NSLocalizedString(#"Details",#"")
style:UIBarButtonItemStyleBordered target:self
action:#selector(detailsPressed)];
detailsButton.width = TOOLBAR_ITEM_WIDTH;
detailsButton.enabled = NO;
toolbar.items = [NSArray arrayWithObjects: flexibleItem, detailsButton, nil];
[flexibleItem release];
[detailsButton release];
[self.view addSubview:toolbar];
[toolbar release];
// More non-related code here
}
#end
Here is its output:
output http://dl.dropbox.com/u/13741164/toolbar.jpg
As you see, details button is out of frame by the right side. The smaller TOOLBAR_ITEM_WIDTH, the more it is inside the frame. So I suppose there is a bug in the calculation of toolbar items, because it works wonderfully in 4.0 sdk, right? Thanks for your help.
The following call fixed the issue for me:
[toolbar sizeToFit];
I used to use the old-school method of adding an overlay to the camera screen, and that worked fine. However, since 3.1 came out, Apple is insisting that I use the API to add an overlay. I quickly got the overlay to work, but it seems that if I use the custom overlay, then the move & resize screen is not responsive, I can only use or retake, can't actually resize & move. The code I am using is below. I have tried several variations, but the only thing that actually enables the move & resize is to remove the line that adds the custom overlay view.
Any ideas?
UIImage *image = [UIImage imageNamed:#"camera-template-long.png"];
UIImageView *imgView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)] ;
imgView.image = image;
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
[overlayView addSubview:imgView];
UIImagePickerController* picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.showsCameraControls = YES;
picker.cameraOverlayView = overlayView;
picker.delegate = self;
picker.allowsEditing = YES;
[self presentModalViewController:picker animated:YES];
Set both allowsEditing/showsCameraControls properties to NO, prepare your original view to cameraOverlayView, and use takePicture method.
Then, imagePickerController:didFinishPickingMediaWithInfo: will be called directly.
Please try the following code:
- (void)foo {
UIImagePickerController *controller = [[[UIImagePickerController alloc] init] autorelease];
controller.sourceType = UIImagePickerControllerSourceTypeCamera;
controller.cameraOverlayView = self.cameraOverlay;
[self performSelector:#selector(moveOverlayViewToSublayer:) withObject:controller afterDelay:0.1f];
controller.delegate = self;
[self presentModalViewController:controller animated:YES];
}
- (void) moveOverlayViewToSublayer:(UIImagePickerController*)controller {
CALayer *aLayer = self.cameraOverlay.layer.superlayer;
controller.cameraOverlayView = nil;
[aLayer addSublayer:self.cameraOverlay.layer];
}
I hope it will work well.
The entire issue goes away once you use [overlayView setUserInteractionEnabled:NO]; to stop the overlay view from handling the input.
http://www.techques.com/question/1-10178214/cameraOverlayView-prevents-editing-with-allowsEditing
This works perfectly for me. I tried to disable userInteractionEnabled but in vain.
This is the strangest error i have come across.
Am trying to add a countdown animation onto a Class that extends UIView. The code is shown below:
NSArray *myImages = [[NSArray alloc] initWithObjects: [UIImage imageNamed:#"3.png"], [UIImage imageNamed:#"2.png"], [UIImage imageNamed:#"1.png"], [UIImage imageNamed:#"Go.png"], nil];
UIImageView *myAnimatedView = [[UIImageView alloc] initWithFrame:CGRectMake(50, 50, 80, 80)];
myAnimatedView.animationImages = myImages;
myAnimatedView.animationDuration = 3;
myAnimatedView.animationRepeatCount = 0;
[self addSubview:myAnimatedView];
[myAnimatedView startAnimating];
It is just not appearing on the screen. Any Ideas?
Have you made sure those images are added to your project?
Can you add them as a flat image (non-animated) -- as in:
UIImageView *myAnimatedView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"3.png"]];
[self addSubview:myAnimatedView];
(just to make sure that works first)?
If, instead of extending UIView, you extended UIImageView, would that make a difference?
Try switching the last 2 lines. From:
[self addSubview:myAnimatedView];
[myAnimatedView startAnimating];
To:
[myAnimatedView startAnimating];
[self addSubview:myAnimatedView];