I have to open camera in my app in small region of screen ,but not getting how to implement it,because camera opens on full screen genreally.
The camera should be open in uiimage view region,Plz guide me how to achieve this.Thanks.
You should take a look at AVCam sample project provided by Apple. It has all the features you need for your task. Good Luck!
I experimented with the code from my last post, and commented out the final scale transform ((the one which makes it full size) and I ended up with a lovely miniature camera imagePicker floating in the middle of my screen, so it definitely does work! The exact code I used, including the zoom/fade-in transition, is -
UIImagePickerController *imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage, nil];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.cameraCaptureMode = UIImagePickerControllerCameraCaptureModePhoto;
UIView *controllerView = imagePickerController.view;
controllerView.alpha = 0.0;
controllerView.transform = CGAffineTransformMakeScale(0.5, 0.5);
[[[[UIApplication sharedApplication] delegate] window] addSubview:controllerView];
[UIView animateWithDuration:0.3
delay:0.0
options:UIViewAnimationOptionCurveLinear
animations:^{
controllerView.alpha = 1.0;
}
completion:nil
];
[imagePickerController release];
you can go through my answer here.
Related
In my iPhone App I need to display a modal view with transparent background and it should appear with animation like it is appearing from center of view and its size is increasing.
similar like "drawing something" iPhone App when we click on settings button.
How do I do this?
You can do one of 4 following transition styles:
viewController.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
viewController.modalTransitionStyle = UIModalTransitionStyleCrossDissolve;
viewController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
viewController.modalTransitionStyle = UIModalTransitionStylePartialCurl;
[self presentModalViewController:viewController animated:YES];
If you want something that is not included in these defaults you are going to have to build your own custom animation for presenting the modal view. Like the following but obviously for the style you want.
UIModalTransitionStyle horizontal movement
Let's say you have a viewController thats called aScoreSheet that you want to present. Try to define this method in the view controller that's going to do the presenting.
-(void) presentTransparentModalViewController: (ScoreSheet *) aViewController
{
scoreSheet = aViewController;
UIView *view = aViewController.view;
view.opaque = NO;
[view.subviews enumerateObjectsUsingBlock:^(id obj, NSUInteger idx, BOOL *stop) {
UIView *each = obj;
each.opaque = NO;
}];
[self.view addSubview:view];
view.center = CGPointMake(160, 800); //for iPhone
[UIView animateWithDuration:0.9 delay:0 options:UIViewAnimationCurveEaseInOut animations:^{
view.center = CGPointMake(160, 240);
} completion:^(BOOL finished) {
self.view.userInteractionEnabled=YES;
}];
}
and then to dismiss the controller:
-(void) dismissTransparentModalViewControllerAnimated:(BOOL) animated{
if (animated) {
[UIView animateWithDuration:0.4
animations:^{
scoreSheet.view.center = CGPointMake(scoreSheet.view.center.x, scoreSheet.view.center.y + 480);
} completion:^(BOOL finished) {
[scoreSheet.view removeFromSuperview];
scoreSheet = nil;
}];
}
}
Not a full answer, but maybe you can take a look at this open source library:
https://github.com/Split82/HMGLTransitions
It has some custom modal transitions, maybe not exactly the one you are looking for, but you can easily add your transition by subclassing HMGLTransition.
Hope this helps
I've got a simple animation running and its moving up and down with a camera view as a background. I am trying to generate more animation at a random rate. Is that possible?
I am running my animation through UIView startAnimation.
NSArray *myImages = [NSArray arrayWithObjects:
[UIImage imageNamed:#"enemyball.png"],
[UIImage imageNamed:#"playerball.png"]
, nil];
//animation of images
UIImageView *animatedView =[UIImageView alloc];
[animatedView initWithFrame:[self bounds]];
animatedView.animationImages = myImages;
animatedView.animationDuration = 0.25; // seconds
animatedView.animationRepeatCount = 0; //0 loops for ever/noted
[animatedView startAnimating];
[self addSubview:animatedView];
//animation movement
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDuration:1];
[UIView setAnimationCurve:1];
[UIView setAnimationRepeatCount:INFINITY];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationBeginsFromCurrentState:YES];
CGAffineTransform transform = CGAffineTransformMakeTranslation(220, 330);
animatedView.transform = transform;
[UIView commitAnimations];
And this is an overlay that I want to display in my camera view.
- (void) viewDidAppear:(BOOL)animated {
enemyBall *overlay = [[enemyBall alloc] initWithFrame:CGRectMake(20, 20, 50, 50)];
//OverlayView *overlay = [[OverlayView alloc] initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, SCREEN_HEIGTH)];
// Create a new image picker instance:
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
// Set the image picker source:
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
// Hide the controls:
picker.showsCameraControls = NO;
picker.navigationBarHidden = YES;
// Make camera view full screen:
picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform, CAMERA_TRANSFORM_X, CAMERA_TRANSFORM_Y);
// Insert the overlay:
//picker.cameraOverlayView = overlay;
picker.cameraOverlayView = overlay;
// Show the picker:
[self presentModalViewController:picker animated:YES];
[super viewDidAppear:YES];
}
I am trying to have my animation generate in a random sequence and timing but placing another set of array code seems too much and I can't have a second overlay because it doesn't read the second overlay. Is this possible?
Ok, so I'm using the ZBar SDK to scan barcodes in my iPhone app. I've successfully implemented the sample code, but now I want to change the frame of the scanner view (i.e: To half the screen size). I've tried setting the frame of the reader's view in viewDidLoad, but it resizes itself.
I know this is going to be one of those really simple things I just missed, but any help would be much appreciated. Cheers.
EDIT: I got it to work. Here's my code:
ZBarReaderViewController *reader = [ZBarReaderViewController new];
reader.readerDelegate = self;
ZBarImageScanner *scanner = reader.scanner;
[reader setShowsZBarControls:NO];
[reader.readerView setScanCrop:(CGRect){ { 0, 0 }, { 0.43, 1 } }];
[reader.readerView start];
[self.view addSubview:reader.view];
overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 460)];
[listTableView setFrame:CGRectMake(0, 208, 320, 208)];
[overlayView addSubview:listTableView];
[self.view addSubview:overlayView];
Instead of using ZBarReaderViewController, try using ZBarReaderView. This worked for me and saved my lot of time. Hope it helps you.
ZBarReaderView*reader = [ZBarReaderView new];
ZBarImageScanner * scanner = [ZBarImageScanner new];
[scanner setSymbology: ZBAR_I25
config: ZBAR_CFG_ENABLE
to: 0];
reader = [reader initWithImageScanner:scanner];
reader.readerDelegate = self;
reader.tracksSymbols = YES;
reader.frame = CGRectMake(20, 38, 283, 347);
reader.torchMode = 0;
dispatch_async(dispatch_get_main_queue(), ^{[reader start];});
[self.view addSubview:reader];
I worked it out. This is what I had to do:
Add ZBarReaderViewController's view as subview of my own view (which annoyingly fills the entire view no matter what its frame is).
Change scan size of ZBarReaderViewController to whatever size I want it to be (BEWARE: Setting this frame is not like setting one normally, just ask if you need help).
Add any views that you want visible to the ZBarReaderViewController's overlay view.
This was very difficult and unintuitive and broke many of Apple's code design guidelines but, in the end, is still doable.
You can create your own view and view controller,and add the ZBarReaderViewController's view as a subview of your own view;
another way to modify the properties of the scanning view controller is to import the ZBarSDK project and compile and link it yourself, rather than using the binary version of the SDK. Then, you can make any changes to the view controller that you need to (keep in mind their license...should probably read that first)
Try this
It may help you:
ZBarReaderViewController *reader= [ZBarReaderViewController new];
reader.readerDelegate = self;
reader.supportedOrientationsMask = ZBarOrientationMaskAll;
ZBarImageScanner *scanner = reader.scanner;
// TODO: (optional) additional reader configuration here
// reader.showsCameraControls = NO; // for UIImagePickerController
reader.showsZBarControls = NO;
// EXAMPLE: disable rarely used I2/5 to improve performance
[scanner setSymbology:ZBAR_I25|ZBAR_QRCODE
config: ZBAR_CFG_ENABLE
to: 0];
[reader viewDidLoad];
[reader viewWillAppear:NO];
[reader viewDidAppear:NO];
[self.viewScan addSubview:reader.view];
here,self.viewScan is any view of your current controller.
so scanning area now self.viewScan view.
The best way to do it so it will be inside a sampleView :
UIView *view = [self sampleView];
CALayer *viewLayer = [view layer];
[viewLayer setMasksToBounds:YES];
CGRect bounds = [view bounds];
[reader.view.layer setFrame:bounds];
[viewLayer insertSublayer:reader.view.layer below:[[viewLayer sublayers] objectAtIndex:0]];
I want to reproduce my iPhone display for demoing purposes. I've tried
this and this, but both give me a black screen. Finally, I headed out to make my own solution. Here's what I have:
// Check for external screen.
if ([[UIScreen screens] count] > 1) {
externalWindow = [[UIWindow alloc] initWithFrame:[[UIScreen mainScreen] bounds]];
// Internal display is 0, external is 1.
externalScreen = [[[UIScreen screens] objectAtIndex:1] retain];
screenModes = [externalScreen.availableModes retain];
UIScreenMode *desiredMode = [screenModes objectAtIndex:0];
externalScreen.currentMode = desiredMode;
externalWindow.screen = externalScreen;
[screenModes release];
[externalScreen release];
CGRect rect = CGRectZero;
rect.size = desiredMode.size;
externalWindow.frame = rect;
externalWindow.clipsToBounds = YES;
externalWindow.hidden = NO;
[externalWindow makeKeyAndVisible];
[externalWindow setUserInteractionEnabled:YES];
[externalWindow setMultipleTouchEnabled:YES];
//[[CCDirector sharedDirector] attachInView:externalWindow];
Now, I can display on the external display or on my iPhone, but I can't display on both at the same time, because [[CCDirector sharedDirector] attachInView:externalWindow]; will only take one UIWindow. How can I get around this and/or get the displayed image and set it to my external display?
Thanks,
Dave
The only solution i see is to render your scene to a texture and render that texture twice as a full screen quad to the backbuffer, once for each UIWindow
I am really trying to do my best but I can't really find out what's going wrong in my code. I made a lot of search but I guess I just can't understand some objective c basics ;)
My first question is related to the code below :
[window addSubview:tabBarController.view];
UIImage *image = [UIImage imageNamed:#"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image];
Does it make a difference doing this :
[window addSubview:defaultImage];
or this :
[tabBarController.view addSubview:defaultImage];
My second question is about creating a splash screen. I tried to do it by myself but I just can't find out what's not working (we're in appDelegate) :
[window addSubview:tabBarController.view];
UIImage *image = [UIImage imageNamed:#"lol.png"];
UIImageView *defaultImage = [[UIImageView alloc] initWithImage:image];
[window addSubview:defaultImage];
[window makeKeyAndVisible]; //makes the window visible right ?
UIImage *image2 = [UIImage imageNamed:#"lol2.png"];
UIImageView *pubImage = [[UIImageView alloc] initWithImage:image2];
[UIView setAnimationDelegate:self];
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:2.0];
[UIView setAnimationTransition:UIViewAnimationTransitionFlipFromLeft forView:window cache:YES]; //not sure about the forView:window ...
[defaultImage removeFromSuperview];
[window addSubview:pubImage];
[UIView commitAnimations];
Hmm, I guess since I called "makekeyandvisible" window should be visible and animation should be showed to users ...
Well, I am missing a step as it doesn't work :D.
Help welcome,
Gauthier.
If you add an image to your project named "Default.png" it will act as a splash screen.
Forcing your user to look at a screen any longer than necessary is typically considered bad.
If you do want to add one anyways using addSubview: should work fine, if you'd like animation you may want to look into CATransitions instead of the UIView animations.
Adding the splash screen to the window or the main view controller should appear the same to the user.
Edit:
Try this snippet -- you'll need to #include <QuartzCore/QuartzCore.h> and add the QuartzCore framework
// Using a CATransition
CATransition* transition = [CATransition animation];
transition.delegate = self; // if you set this, implement the method below
transition.duration = 0.3;
transition.timingFunction = [CAMediaTimingFunction functionWithName: kCAMediaTimingFunctionEaseOut];
transition.type = kCATransitionMoveIn;
transition.subtype = kCATransitionFromRight;
[self.view.layer addAnimation: transition forKey: nil];
[self.view addSubview: theNewView];
Add this if you need to do something when the transition is finished:
#pragma mark -
#pragma mark CAAnimation Delegate Methods
- (void)animationDidStop: (CAAnimation*)theAnimation finished: (BOOL)flag
{
// Whatever you need to do when the animation is done.
}
I don't agree with the first statement in the other answer, that says 'If you add an image to your project named "Default.png" it will act as a splash screen.'
Default.png is the launch image. The Apple HIG specifically distinguishes between launch image and splash screen.
In particular, it says
Avoid using your launch image as an opportunity to provide:
An “application entry experience,” such as a splash screen
An About window
Branding elements, unless they are a static part of your application’s first screen
Hence, for a splash screen, use NSTimer or a button for the user to dismiss the splash screen.