cameraOverlayView problem on iOS 4.3 - iphone

I'm using an picker Controller with a cameraOverlayView to display an image of a product in the camera view. The product image is resized before applying on the overlay.
It works fine on iOS 4.2 but on iOS 4.3 the product image is displayed full size.
pickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
UIImageView *imgView = [[[UIImageView alloc] initWithImage:[UIImage imageNamed:produitAffiche.img_realite]] autorelease];
// Resize
if(imgView.frame.size.height == 480)
{
//Portrait
imgView.frame = CGRectMake(80.0f, 120.0f, 160.0f, 240.0f);
}
else
{
// Landscape
imgView.frame = CGRectMake(40.0f, 160.0f, 240.0f, 160.0f);
}
imgView.contentMode = UIViewContentModeCenter;
imgView.clipsToBounds = NO;
imgView.contentMode = UIViewContentModeScaleAspectFit;
pickerController.cameraOverlayView = (UIView *) imgView;
I changed the frame of the UIImageView I use as overlay but it's still displayed at 320*480.
I know that the cameraOverlayView have been modified in iOS 4.3 but I don't know what has changed and what I have to do to correct my application.
Thanks for your help.

In iOS 4.3 the overlay view is stretched to full screen. Because you set the content mode to aspect fit, the image is stretched to fit the new view size which is 320x480.
You need to make a transparent UIView that is fullscreen, add the imageview to that view and make the UIView the new overlay view.
UIView *fullscreenView = [[UIView alloc] initWithFrame:CGRectZero];
fullscreenView.backgroundColor = [UIColor clearColor];
....
[fullscreenView addSubview:imgView];
pickerController.cameraOverlayView = fullscreenView;

Found this article that seems to fit the bill. The long and short of it is to use
- (UIImage *)
resizedImageWithContentMode:(UIViewContentMode)contentMode
bounds:(CGSize)bounds
interpolationQuality:(CGInterpolationQuality)quality;

Comment out this line in your code
imgView.clipsToBounds = NO;
It should work.
If you really want to clip, #slf 's answer should help.

try setting these properties of UIImagePicker:
mImagePickerController.showsCameraControls = NO;
mImagePickerController.navigationBarHidden = YES;
mImagePickerController.toolbarHidden = YES;
mImagePickerController.wantsFullScreenLayout = YES;

My problem was actually that a UIImagePicker displayed full-screen on iOS5 did not work on iOS4.3, on an iPad. I was starting the image picker up offscreen, then animating it into view... You would see the shutter image open up, but then the camera view itself was simply transparent with no camera output.
My solution was to not animate that in for iOS4.3 on the iPad. It seems that having the camera view started offscreen was leaving the camera rendering part behind (fixed as I noted in iOS5).
This answer is not quite right for the original question but I place it here for someone that comes into the same issue and hits this question as I did.

Related

Make TableView background not scrollable

today I've an other problem: I add a background image to a table view and I like that stay stationary when the cells scroll. I found this
self.tableView.backgroundView = [[UIImageView alloc] initWithImage:
[UIImage imageNamed:#"background.png"]];
here iPhone Fixed-Position UITableView Background.
but I'm not able to "translate" from Objective-c to Swift... so can anyone help me?
You could try something like this.
var view = UIImageView(frame: /*whatever you want your frame to be*/)
view.image = //whatever you want your image to be
tableView.backgroundView = view

title of the subview covered by background image of that subview (iphone)

I have a subview on my main view which pops up using tap.
I set a background image to it but now the title is covered . what do I need to do to fix this? SHOULD I change anything in viewDidLoad?
here is how I have added the background image:
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"test.png"]];
imageView.frame = CGRectMake(0.0, ViewHeight, kDeviceWidth, 230.0);
container.opaque = NO;
container.backgroundColor = [UIColor clearColor];
[self.formView addSubview:imageView];
[self.formView addSubview:frame];
If you want to add title on top of background image then you need to add title to image view like this
[imageView addSubview title];
if you want to add title on top of form view then do this
[self.formView addSubview:imageView];
[self.formView addSubview:title];
Hope it helps.
Every layer has property called zPosition. By changing zPosition you can manipulate the order of drawing the layers.
CALayers with greater zPosition cover the CALayers, that have smaller zPosition. zPosition is by default 0, so setting -1 value for the background image layer should work.
To change this property you have to use QuartzCore framework: click on Project - Targets - ProjectName - Build Phases - Link Binary With Libraries - Plus - QuartzCore.
#include <QuartzCore/QuartzCore.h>
imageView.layer.zPosition = -1;

iphone: displaying small, live camera image in window (2)

I am having a great deal of trouble displaying at small, live camera image in a viewController.
I would have expected the following code to show camera display to appear in a 100x 100 window, but it keeps appearing full screen!
Help appreciated.
camera = [[UIImagePickerController alloc] init];
UIView *cameraHUD = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 100, 100)];
cameraHUD.userInteractionEnabled = YES;
[camera setSourceType:UIImagePickerControllerSourceTypeCamera];
camera.showsCameraControls = NO;
camera.navigationBarHidden = YES;
camera.toolbarHidden = YES;
camera.cameraOverlayView = cameraHUD;
[self presentModalViewController:camera animated:YES];
[self.view bringSubviewToFront:cameraHUD];
You are present a new view instead of your actual view, so by default a new UIView has contentmode= scale to fill.
You have to add for example something like:
[camera setContentMode:UIViewContentModeTopLeft];
But if you want do something cool you have to add your Camera View as subview.
I hope it can help you
bye ;)

UIImagePicker and overlays

In my app, after an image is picked with uiimagepicker, it is processed via a webservice. The web processing takes a second, so I'd like to create an grayed out overlay with an activity indicator view.
My problem is that the UIImagePickerView view seems to stay on top of everything until the processing is finished.
I have tried using [myPicker dismissModalViewControllerAnimated:YES]; before the overlay is loaded or the processing even starts, but the view is still on screen. After that, my overlay is loaded as followed
ovController = [[OverlayViewController alloc] initWithNibName:#"OverlayViewController" bundle:[NSBundle mainBundle]];
CGFloat yaxis = self.navigationController.navigationBar.frame.size.height;
CGFloat width = self.view.frame.size.width;
CGFloat height = self.view.frame.size.height;
CGRect frame = CGRectMake(0, yaxis, width, height);
ovController.view.frame = frame;
ovController.view.backgroundColor = [UIColor grayColor];
ovController.view.alpha = 0.7;
[self.view insertSubview:ovController.view aboveSubview:self.view];
I have also tried using [[myPicker cameraOverlayView] insertSubview:ovController.view]; before I dismiss myPicker, but to no avail.
To be clear, I am trying bring the "loading" overlay on the screen after the UIImagePicker goes away, but before the web processing starts.
Any input will be appreciated. Thanks
It sounds like you are doing the upload on the main thread which is locking the view from being updated. You might try doing the upload on a sperate thread so that the main thread can dismiss the image picker and display the overlay.

Proper fill an image larger than screen

What I wanted to achieve here is simply fit the image width to the screen on both orientations and use UIScrollView to just allow scroll vertically to see the whole image.
Both viewController and view are created pragmatically.
The image loaded is larger than screen on both width and height.
Here is the related code in my viewController:
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation
{
return YES;
}
- (void)loadView {
UIScreen *screen = [UIScreen mainScreen];
CGRect rect = [screen applicationFrame];
self.view = [[UIView alloc] initWithFrame:rect];
self.view.contentMode = UIViewContentModeScaleAspectFill;
self.view.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
UIImage *img=[[UIImage alloc] initWithContentsOfFile:[[NSBundle mainBundle] pathForResource:#"image" ofType:#"png"]];
UIImageView *imgView =[[UIImageView alloc] initWithImage:img];
[img release];
imgView.contentMode = UIViewContentModeScaleAspectFill;
imgView.autoresizingMask = UIViewAutoresizingFlexibleWidth | UIViewAutoresizingFlexibleHeight;
[self.view addSubview:imgView];
[imgView release];
}
I tried all combinations for both contentMode above, did not give me correct result.
The most close I am getting now: I manually resize imgView in loadView, portrait mode would display correctly since app always starts with portrait mode, but in landscape mode, the width fits correctly, but image is centered vertically rather than top aligned.
If I add the imgView to a scrollView, in landscape mode it looks like contentSize is not set to full image size. but when I scroll bounce I can see the image is there in full size.
Questions:
why I need to resize it manually?
in landscape mode how and where I can 'move' the imgView, so imgView.frame.origin is (0,0) and works correctly with a scroll view?
Update
I added:
imgView.clipsToBounds = YES;
and find out in landscape mode the image bounds is smaller than screen in height.
So the question becomes how to have the image view keeps original ratio (thus shows the full image always) when rotated to landscape? Do I need to manually resize it after rotation again?
Instead of manually take care of orientation change and change view details. I plan to follow Apple document and make separate view controllers for each orientations.
see P42 # ViewControllerProgrammingGuide:
Creating an Alternate Landscape Interface
Here in the code you are not using any scrollView.
You need to add that imageView to ScrollView. and set the scrollView frame as same as the main view and contentSize to imageView or image Size.
If you are using scroll view in the app, then have you also resized the scroll view and the subviews as well, your code if fine just try to resize the subviews as well.
I use the following code to do so.
self.homescroll.autoresizingMask=UIViewAutoresizingFlexibleWidth |UIViewAutoresizingFlexibleHeight;// | UIViewAutoresizingFlexibleRightMargin |UIViewAutoresizingFlexibleLeftMargin;
self.homescroll.autoresizesSubviews=YES;
[self.homescroll setNeedsLayout];
[self.view addSubview:homescroll];
Just resize the subviews as well.