I have an Ipad application in which i am trying to do some barcode reading processes.when i am pressing a button in the home page i am presenting the barcode reading viewcontrollers view like this`
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.sourceType=UIImagePickerControllerSourceTypeCamera;
//reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
reader.cameraOverlayView=cameraOverlay;
if( [UIImagePickerController isCameraDeviceAvailable: UIImagePickerControllerCameraDeviceFront ])
{
reader.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
ZBarImageScanner *scanner = reader.scanner;
reader.wantsFullScreenLayout = YES;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader.showsZBarControls = NO;
// present and release the controller
[self presentModalViewController:reader animated:YES];
//[appdel.navigationController pushViewController:reader animated:YES];
//[reader.view addSubview:collect];
[reader.view addSubview:back];
[back addTarget:self action:#selector(backpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader.view addSubview:scan];
[scan addTarget:self action:#selector(getpressed:) forControlEvents:UIControlEventTouchUpInside];
[reader release];
and when i am pressing the scan button added to the reader view i need to add another view.for that i am doing -(IBAction)getpressed:(id)sender{[self.view addSubview:newview] }.but it is not added to the view.can anybody help me to achieve this?
`
you need to overlay to your zbar view and add that button overlay view:
//set the frame according to your requirement
aOverlay = [[UIView alloc] initWithFrame:CGRectMake(0.0,0.0,320.0,480.0)];
aOverlay.backgroundColor = [UIColor clearColor];
UIButton *aBtnscan = [UIButton buttonWithType:UIButtonTypeRoundedRect];
[aBtnscan setFrame:CGRectMake(115, 435, 80, 45)];
[aBtnscan addTarget:self action:#selector(getpressed:)forControlEvents:UIControlEventTouchUpInside];
[aOverlay addSubview:aBtnscan];
reader.cameraOverlayView = aOverlay;
// You code
Related
I'm playing around with a cameraOverLayView and encountered a weird behavior. Before presenting the UIImagePickerController, I set allowsEditing to YES. After the capture screen comes up, I tap on a button that triggers takePicture(). Instead of presenting the editing screen, the delegate method didFinishPickingMediaWithInfo() gets called right away. Can anyone help me figure out what I could be doing wrong? I pasted some of my code below...
Thanks!
- (BOOL)shouldStartCameraController {
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera] == NO) {
return NO;
}
CGSize screenSize = [[UIScreen mainScreen] bounds].size;
float overlayOffset = 0;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPhone) {
if (screenSize.height > 480.0f) {
overlayOffset = 195;
} else {
overlayOffset = 103;
}
} else {
/*Do iPad stuff here.*/
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]
&& [[UIImagePickerController availableMediaTypesForSourceType:
UIImagePickerControllerSourceTypeCamera] containsObject:(NSString *)kUTTypeImage]) {
cameraUI.mediaTypes = [NSArray arrayWithObject:(NSString *) kUTTypeImage];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceRear]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceRear;
} else if ([UIImagePickerController isCameraDeviceAvailable:UIImagePickerControllerCameraDeviceFront]) {
cameraUI.cameraDevice = UIImagePickerControllerCameraDeviceFront;
}
} else {
return NO;
}
UIView *cameraOverlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height)];
UIImageView *cameraOverlayImageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"iphone5_camera_overlay.png"]];
cameraOverlayImageView.frame = CGRectMake(0, 0, cameraUI.view.frame.size.width, cameraUI.view.frame.size.height);
[cameraOverlayView addSubview:cameraOverlayImageView];
UILabel *cameraLabel = [[UILabel alloc] initWithFrame:CGRectMake( 0.0f, self.view.bounds.size.height-overlayOffset, self.view.bounds.size.width, 50.0f)];
[cameraLabel setTextAlignment:NSTextAlignmentCenter];
[cameraLabel setBackgroundColor:[UIColor clearColor]];
[cameraLabel setTextColor:[UIColor whiteColor]];
[cameraLabel setShadowColor:[UIColor colorWithWhite:0.0f alpha:0.300f]];
[cameraLabel setShadowOffset:CGSizeMake( 0.0f, -1.0f)];
[cameraLabel setFont:[UIFont boldSystemFontOfSize:18.0f]];
[cameraOverlayView addSubview:cameraLabel];
UIButton *cancelButton = [UIButton buttonWithType:UIButtonTypeCustom];
[cancelButton addTarget:self action:#selector(cancelButtonPressed:) forControlEvents:UIControlEventTouchDown];
[cancelButton setFrame:CGRectMake(10, cameraOverlayView.frame.size.height-60, 50, 50)];
[cancelButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:cancelButton];
UIButton *snapButton = [UIButton buttonWithType:UIButtonTypeCustom];
[snapButton addTarget:self action:#selector(takePictureButtonPressed:) forControlEvents:UIControlEventTouchDown];
[snapButton setFrame:CGRectMake(110, cameraOverlayView.frame.size.height-60, 100, 50)];
[snapButton setBackgroundColor:[[UIColor whiteColor] colorWithAlphaComponent:0.5f]];
[cameraOverlayView addSubview:snapButton];
cameraUI.allowsEditing = YES;
cameraUI.showsCameraControls = NO;
cameraUI.delegate = self;
self.imagePickerController = cameraUI;
[self presentModalViewController:cameraUI animated:YES];
return YES;
}
- (void)handleGesture:(UIGestureRecognizer *)gestureRecognizer {
[self shouldPresentPhotoCaptureController];
}
#pragma mark - UIBarButton Selectors
- (void)takePictureButtonPressed:(id)sender {
NSLog(#"takePictureButtonPressed...");
// TODO: take picture!
[self.imagePickerController takePicture];
}
Possible dublicate: How do I use [camera takePhoto] and edit using UIImagePicker - UIImagePickerController.allowsEditing = YES
According to takePicture: method in Apple documentation:
Use this method in conjunction with a custom overlay view to initiate the programmatic capture of a still image. This supports taking more than one picture without leaving the interface, but requires that you hide the default image picker controls.
Calling this method while an image is being captured has no effect. You must wait until the associated delegate object receives an imagePickerController:didFinishPickingMediaWithInfo: message before you can capture another picture.
It seems that this approach (custom overlay) it is configured in order to be managed by yourself. Even if "allowsEditing = YES" the taken picture will be directly sent to imagePickerController:didFinishPickingMediaWithInfo:.
Based on that if we want to edit the taken picture using our custom user interface we should create an according custom edit screen for that purpose.
How can we bring rectangle on camera for barcode scanning like red laser with scanningound? is there any built in property?I tried following:
reader.readerView.tracksSymbols = YES;
reader.readerView.trackingColor = [UIColor redColor];
[reader setShowsZBarControls:NO];
reader.readerView.tracksSymbols = TRUE;
scanner.accessibilityFrame = CGRectMake(100, 100, 200, 300);
Add the rectange as an overlay on your camera view.Here is the code:
- (IBAction) scanButtonTapped
{
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
reader.showsZBarControls = NO;
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: YES];
reader.cameraOverlayView = [self CommomOverlay];
[reader release];
}
-(UIView*)CommomOverlay{
UIView* view = [[UIView alloc] initWithFrame:CGRectMake(0,0,320,480)];
UIImageView *FrameImg = [[UIImageView alloc] initWithFrame:CGRectMake(70,160,203,180)];
[FrameImg setImage:[UIImage imageNamed:#"overlaygraphic.png"]];
[view addSubview:FrameImg];
return view;
}
hope this will help you..:)
Did you try
reader.cameraOverlayView = overLayView;
?? i.e cameraOverlayView property of UIImagePickerController.
There you can set what ever you want. Hope this is what you want.
I am running into an issue that seems so simplistic, is frustrating. I am using the zbar library to play around with scanning qr-codes. Here is my code:
- (IBAction)scanButtonTapped:(id)sender {
// ADD: present a barcode reader that scans from the camera feed
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
reader.showsZBarControls = NO;
UIButton *overlay = [UIButton buttonWithType:UIButtonTypeCustom];
overlay.frame = CGRectMake(0, 0, 320, 480);
[overlay setImage:[UIImage imageNamed:#"CameraCover.png"] forState:UIControlStateNormal];
reader.cameraOverlayView = overlay;
overlay.userInteractionEnabled = YES;
[overlay addTarget:self action:#selector(beginScanning:) forControlEvents:UIControlEventTouchUpInside];
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
// present and release the controller
[self presentModalViewController: reader
animated: NO];
[reader release];
}
- (void) imagePickerController: (UIImagePickerController*) reader
didFinishPickingMediaWithInfo: (NSDictionary*) info
{
// ADD: get the decode results
id<NSFastEnumeration> results =
[info objectForKey: ZBarReaderControllerResults];
ZBarSymbol *symbol = nil;
for(symbol in results)
// EXAMPLE: just grab the first barcode
break;
// EXAMPLE: do something useful with the barcode data
resultText.text = symbol.data;
// EXAMPLE: do something useful with the barcode image
resultImage.image =
[info objectForKey: UIImagePickerControllerOriginalImage];
// ADD: dismiss the controller (NB dismiss from the *reader*!)
[reader dismissModalViewControllerAnimated: YES];
[self pushNewScreen];
}
-(void) pushNewScreen
{
MainViewController *mainView = [[MainViewController alloc] initWithNibName:#"MainViewController" bundle:nil];
[self presentModalViewController:mainView animated:YES];
[mainView release];
}
The problem is, when pushNewScreen is called, mainView is not shown... I have gone through each line with the debugger and every line in pushNewScreen is called. Any ideas?
Instead of [self pushNewScreen]; use [self performselector:#selector(pushNewScreen) after delay:0.5f];
It will solve the problem. If not, increase the delay timing.
Thanks to A-Live, I was able to solve it using
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
instead. Hope this helps someone else!
How can i make controller1 slide up and down by creating slider in it
-(void)actionSheet:(UIActionSheet *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0:{
//Devanagari view display
ButtonViewController *controller1 = [[ButtonViewController alloc]init];
controller1.delegate = self;
UINavigationController *navigationController = [[UINavigationController alloc]
initWithRootViewController:controller1];
navigationController.navigationBar.tintColor = [UIColor colorWithHue:2.0/12 saturation:2.0 brightness:4.0/10 alpha:1.0];
[self presentModalViewController:navigationController animated:YES];
[navigationController release];
break;
}
I got this from User Experience Coding How-To's from Apple Reference for creating slider
CGRect frame = CGRectMake(0.0, 0.0, 200.0, 10.0);
UISlider *slider = [[UISlider alloc] initWithFrame:frame];
[slider addTarget:self action:#selector(sliderAction:) forControlEvents:UIControlEventValueChanged];
[slider setBackgroundColor:[UIColor clearColor]];
slider.minimumValue = 0.0;
slider.maximumValue = 50.0;
slider.continuous = YES;
slider.value = 25.0;
I added this whole thing right below UIText View in controller1 but controller1 is not sliding up and down.
Appreciate help.
From what I can tell about what you are trying to do, I think you should be using a UIScrollView and taking control of its contentOffset property. I threw together a quick example app, hopefully its what you are trying to do.
http://cl.ly/2Z3D1D0W1m332y313v0A
I was wondering which method is the easiest or "smartest" way of making a pause menu for games?
I don´t have that much experience with creating game pause menus so I´ve tried 2 methods that I came up with by my own. Both or in code beneath this text.
The first method I tried was to put a black almost transparent filter on top of the game, that I paused. I was successful with pausing everything except the touches made underneath the filter on my uiimages. I thought that putting a new uiimage on top of the current one would disable the touches made on the uiimages underneath it. I tried as well with touchenabled = NO but still nothing.
-(IBAction)pause{
NSLog(#"pause");
[countdowntimer invalidate];
[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];
[self.rubin3 stopAnimating];
Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;
//PauseMenu background
UIImage *image1 = [UIImage imageNamed: #"filter2.png"];
pausefilter = [[[UIImageView alloc] initWithImage:image1] autorelease];
CGRect newFrame1 = pausefilter.frame;
newFrame1 = CGRectMake(0,0, image1.size.width, image1.size.height);
pausefilter.frame = newFrame1;
[self.view addSubview:pausefilter];
[image1 release];
//Resume to Game
button1 = [UIButton buttonWithType:UIButtonTypeCustom];
button1.frame = CGRectMake(90, 146, 80, 18);
[button1 setImage:[UIImage imageNamed:#"RESUME.png"] forState:UIControlStateNormal];
[button1 addTarget:self action:#selector(resume) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button1 ];
//End Game
button2 = [UIButton buttonWithType:UIButtonTypeCustom];
button2.frame = CGRectMake(260, 140, 180, 30);
[button2 setImage:[UIImage imageNamed:#"EndGame.png"] forState:UIControlStateNormal];
[button2 addTarget:self action:#selector(end) forControlEvents:UIControlEventTouchUpInside];
[ self.view addSubview: button2 ];
[sharedSoundManager pausePlayingMusic];
}
The second method I tried was to go back (switch view) to the options on the main menu to use the settings from there instead but I wasn´t able to resume back to where I paused the game. Instead the game restarted from the beginning.
-(IBAction)pause{
NSLog(#"pause");
[countdowntimer invalidate];
[self.rubin1 stopAnimating];
[self.rubin2 stopAnimating];
[self.rubin3 stopAnimating];
Pause.enabled = NO;
music1.enabled = NO;
music2.enabled = NO;
sfx1.enabled = NO;
sfx2.enabled = NO;
menureturn = [[MainMenu alloc] initWithNibName:#"MainMenu" bundle: nil];
menureturn.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
[self presentModalViewController:menureturn animated: YES];
self.menureturn.Start.hidden = YES;
self.menureturn.option.hidden = YES;
self.menureturn.OptionsHeadtitle.hidden = NO;
self.menureturn.HowToPlayHeadtitle.hidden = YES;
self.menureturn.howtoplay.hidden = YES;
self.menureturn.filter.hidden = NO;
self.menureturn.music1.hidden = NO;
self.menureturn.music2.hidden = YES;
self.menureturn.SFXimage.hidden = NO;
self.menureturn.Musicimage.hidden = NO;
self.menureturn.sfx1.hidden = NO;
self.menureturn.sfx2.hidden = YES;
self.menureturn.credits.hidden = YES;
self.menureturn.back.hidden = YES;
self.menureturn.creditsinfo.hidden = YES;
self.menureturn.resume.hidden = NO;
self.menureturn.endgame.hidden = NO;
[sharedSoundManager pausePlayingMusic];
}
Is there a third option of how to make a god pause menu or just redo one of the two I already tried?
You can have a BOOL variable like
BOOL isGamePaused
Now when you are playing game i.e running not paused assign
isGamePaused = NO;
While you pause
isGamePaused = YES;
Now while playing animation or something like that you can use condition like
if(!isGamePaused) { ProceedAnimation;}
Hope this helps
The best thing to disable any event is to create a new element in your pause menu which will be the first responder and catches all events. So nothing can arrive to your game's interface ;)