After testing my App on iOS 4.3 I noticed that the camera overlay of my UIImagePickerController has an added transformation that stretched the content extremely. Pre iOS 4.3 everything shows up correctly.
Here is what I do
imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
cameraOverlay.backgroundColor = [UIColor clearColor];
cameraOverlay.userInteractionEnabled = NO;
//add subviews to camera Overlay
imagePicker.cameraOverlayView = pauseButton;
Any ideas what I have to do to get rid of the added transformation?
OK found the answer. ios 4.3 requires to have the camerOverlay as big as the screen is. So my 200x200 camera overlay was enlarged.
If I change the line:
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 200, 200)];
to
cameraOverlay = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
it works :).
Related
I have an imageView. I need to restrict the size of imageView to the white background imageOnly.The image is tightly bounded between right,left and top margin. I am confused on how to do at bottom, such that the image must fit in the white background only. How do I do that ?
http://i.stack.imgur.com/ztvQe.png
The code I am using
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(25, 240,175,205)];
Frame width and height is 205*205
You can add your imageView as a subview of the view with the white background.
UIView *whiteBackgroundView = [[UIView alloc] initWithFrame:CGRectMake(25,240,205,205)];
CGSize whiteSize = whiteBackgroundView.frame.size;
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0,size.width,size.height)];
[whiteBackgroundView addSubview:_imageView];
In the example your imageView will completely fit the size of the white background view.
Try this
UIView *productView = [[UIView alloc]initWithFrame:CGRectMake(25, 240,225,225)];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,205,205)];
_imageView.clipsToBounds =YES;
[productView addSubview:_imageView];
[self.view addSubview:ImageBackview];
just create one view and add this image in it, for example use bellow code..
UIView *ImageBackview = [[UIView alloc]initWithFrame:CGRectMake(25, 240,225,225)];
_imageView = [[UIImageView alloc] initWithFrame:CGRectMake(10, 10,205,205)];
[ImageBackview addSubview:_imageView];
[self.view addSubview:ImageBackview];
i am adding a label to camera overlay and i successfully added it
but what i am facing is the label is also appearing in preview of the taken picture
i want to display the label in camera overlay not in preview of the taken picture for adding label i am using the following code
UIView *overlayView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 320, 480)];
overlayView.opaque = NO;
overlayView.backgroundColor = [UIColor clearColor];
[overlayView addSubview:topImgView];
[overlayView addSubview:btnInfo];
[overlayView bringSubviewToFront:btnInfo];
UILabel *label =[[UILabel alloc]initWithFrame:CGRectMake(20, 0,290,150)];
label.text =#"Hold the bottle steady, left align the prescription label, and then take the photo";
label.backgroundColor = [UIColor clearColor];
label.numberOfLines = 2;
label.textAlignment = UITextAlignmentCenter;
label.font = [UIFont boldSystemFontOfSize:14.0];
label.textColor = [UIColor whiteColor];
[overlayView addSubview:label];
_infoLabel =label;
[label release];
//Image picker
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePicker.delegate = self;
imagePicker.cameraOverlayView=overlayView;
[self presentModalViewController:imagePicker animated:YES];
_imagePicker =imagePicker;
[imagePicker release];
[topImgView release];
[overlayView release];
can any one please help me how to do that thing...
You need to crop the image based on your overlay dimensions. You could try this tutorial which provides a good explanation.
Beginning iOS4.0, the images captured from camera are saved along with their exif data and rotation information. So, you cannot crop them in the standard way as you would with the UIImages The link above deals specifically with images captured from camera.
What I am trying to achieve is an if statement which finds out if AirPlay is enabled or not.
I know that the property is allowsAirPlay and that it comes from MPVolumeView. But I am stuck from here on in. Any help is much appreciated!
if (allowsAirPlay){
UIImageView *streamBG = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"img1.jpg"]];
[self.view addSubview:streamBG];
[self.view sendSubviewToBack:streamBG];
streamBG.frame = CGRectMake(0, 0, 320, 480);
[streamBG release];
} else {
UIImageView *emailBG_AP = [[UIImageView alloc]
initWithImage:[UIImage imageNamed:#"background_schedule.jpg"]];
[self.view addSubview:emailBG_AP];
[self.view sendSubviewToBack:emailBG_AP];
emailBG_AP.frame = CGRectMake(0, 0, 320, 480);
[emailBG_AP release];}
}
allowsAirPlay is a property in MPMoviePlayerController which you can flip YES and NO. The value won't tell you whether there are AirPlay enabled devices in range. I don't think there are public APIs that tell give you that information.
Can someone show me how I can get a UIPickerView working on the iPad? I'm trying to have a UIPickerView in the middle of the screen. Here is the current code I have:
if(IDIOM == IPAD)
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(200, 345, 400, 216)];
else
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 245, 0, 0)];
namePickerView.delegate = self;
namePickerView.showsSelectionIndicator = YES;
So this just puts the picker view on the far left. On the iPhone, everything is perfect. But on the iPad, this doesn't work. As soon as I try to scroll through the values, nothing movies. The UIPickerView does not respond to any touches. What is the issue here? I just want to put a UIPickerView of default size in the middle of my iPad screen, 345 pixels down.
UIPickerViews on the ipad don't have a default size (ie width).
change
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 0, 0)];
to
namePickerView = [[UIPickerView alloc] initWithFrame:CGRectMake(0, 345, 400, 216)];
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.