UITextView & UITextField get refreshed when pick image from camera from iPhone device - iphone

Facing some weird moment of my career. I have some uitextfield's and one uitextview in my UIViewController....everything works fine on simulator and iPhone 4 iOS v 4.3.5. But in iPhone 4 iOS v 4.0.1 sometimes I get whole view refreshed. That meant sometimes my uitextfields & uitextview lost text after picking image from camera.....
for solving this my attempt was when view disappear I saved values in some array..... and when view did appear i show array values to textboxes.....its works fine with simulator too. but this time my apps get stucked on iPhone 4 iOS v 4.0.1.
- (void)alertView:(UIAlertView *)actionSheet clickedButtonAtIndex:(NSInteger)buttonIndex {
NSLog(#"title : %#",actionSheet.title);
if (![actionSheet.title isEqualToString:#"Success"] && ![actionSheet.title isEqualToString:#"Error"] && ![actionSheet.title isEqualToString:#"خطأ"]) {
if(buttonIndex == 1) {
if([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypePhotoLibrary])
{
UIImagePickerController *picker= [[UIImagePickerController alloc]init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
[self presentModalViewController:picker animated:YES];
[picker release];
}
} else {
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.allowsImageEditing = YES;
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController: picker animated:YES];
[picker release];
}
}
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)img editingInfo:(NSDictionary *)editInfo {
float actualHeight = img.size.height;
float actualWidth = img.size.width;
float imgRatio = actualWidth/actualHeight;
float maxRatio = 320.0/480.0;
if(imgRatio!=maxRatio){
if(imgRatio < maxRatio){
imgRatio = 480.0 / actualHeight;
actualWidth = imgRatio * actualWidth;
actualHeight = 480.0;
}
else{
imgRatio = 320.0 / actualWidth;
actualHeight = imgRatio * actualHeight;
actualWidth = 320.0;
}
}
CGRect rect = CGRectMake(0.0, 0.0, actualWidth, actualHeight);
UIGraphicsBeginImageContext(rect.size);
[img drawInRect:rect];
UIImage *image = UIGraphicsGetImageFromCurrentImageContext();
UIGraphicsEndImageContext();
if(imageCount == 1){
self.firstImage = image;
self.previewImage1.image =firstImage;
}else if(imageCount == 2){
self.secondImage = image;
self.previewImage2.image =secondImage;
}else if(imageCount == 3){
self.thirdImage = image;
self.previewImage3.image =thirdImage;
}else if(imageCount == 4){
self.fourthImage = image;
self.previewImage4.image =fourthImage;
}
[myImageNames replaceObjectAtIndex:imageCount-1 withObject:#"Assigned"];
[[picker parentViewController] dismissModalViewControllerAnimated:YES];
}

Solved..Deleted app from device. then restarted device and install build again....
Now no problem with uitextfield refresh on picking image from camera..
chill guys....:-)

Related

UIImagePickerController Low Memory crash at ios7 on iPad Mini

My app works fine on all the devices and ios versions but when it comes to ipad mini, on iOS7 when i alloc:init the UIImagePickerController and display. After getting image the app suddenly give low memory warning and crash. Here is my code of capturing image.
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIImagePickerController *imagePickerController;
if ([UIUtilityClass isCurrentVersionIsIOS7OrGreater]) {
UIImagePickerController* imagePickerController = [[UIImagePickerController alloc] init];
[imagePickerController setDelegate:self];
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage,nil];
imagePickerController.allowsEditing=NO;
CGFloat scaleFactor=1.3f;
switch ([UIApplication sharedApplication].statusBarOrientation) {
case UIInterfaceOrientationLandscapeLeft:
imagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * 90 / 180.0), scaleFactor, scaleFactor);
break;
case UIInterfaceOrientationLandscapeRight:
imagePickerController.cameraViewTransform = CGAffineTransformScale(CGAffineTransformMakeRotation(M_PI * -90 / 180.0), scaleFactor, scaleFactor);
break;
case UIInterfaceOrientationPortraitUpsideDown:
imagePickerController.cameraViewTransform = CGAffineTransformMakeRotation(M_PI * 180 / 180.0);
break;
default:
break;
}
}
else
{
imagePickerController = [[NonRotatingUIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypeCamera;
imagePickerController.mediaTypes = [NSArray arrayWithObjects:(NSString *)kUTTypeImage,nil];
imagePickerController.allowsEditing = YES;
}
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePickerController];
popoverController.delegate=self;
[popoverController presentPopoverFromRect:CGRectMake(626,142,120,135) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
[imagePickerController release];
newMedia = YES;
}
After that i capture the image using following code.
-(void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[popoverController dismissPopoverAnimated:true];
[popoverController.delegate popoverControllerDidDismissPopover:popoverController];
UIImage *image = [info objectForKey:UIImagePickerControllerOriginalImage];
int orientation=image.imageOrientation;
image=[image imageToFitSize:PIC_SIZE method:MGImageResizeCrop];
switch (orientation) {
case UIImageOrientationUp:
// do nothing
break;
case UIImageOrientationDown:
image=[image imageRotatedByDegrees:180.0];
break;
case UIImageOrientationLeft:
image=[image imageRotatedByDegrees:90.0];
image=[image imageRotatedByDegrees:180];
break;
//2
case UIImageOrientationRight:
image=[image imageRotatedByDegrees:-90.0];
image=[image imageRotatedByDegrees:180];
break;
default:
break;
}
}
Did you test it without the release call to the imagePickerController? If you are using ARC, I don't think you need to do this.

dismissModelViewControllerAnimated not working for iPhone 5

So in my iPhone 4 device after I pick a image I want the image picker popover to go away. This works in iPhone 4 but the following code doesn't work for the iPhone 5.
- (void) loadImage:(UIImage*) image {
float w = image.size.width;
float h = image.size.height;
float maxw = scrollView.frame.size.width;
float maxh = scrollView.frame.size.height;
float wratio = maxw / w;
float hratio = maxh / h;
float ratio = wratio < hratio ? wratio : hratio;
ratio = ratio < 1 ? ratio : 1;
int adjW = (int) (w * ratio);
int adjH = (int) (h * ratio);
UIGraphicsBeginImageContext(CGSizeMake(adjW, adjH));
CGContextRef context = UIGraphicsGetCurrentContext();
[image drawInRect:CGRectMake(0, 0, adjW, adjH)];
CGImageRef scaledImage = CGBitmapContextCreateImage(context);
UIGraphicsEndImageContext();
[appDelegate.model setCurrentImage:[UIImage imageWithCGImage: scaledImage]];
[self clear];
calcButton.enabled = YES;
trashButton.enabled = YES;
scribbleControls.enabled = YES;
[appDelegate.mergeViewCtlr setFirst];
}
- (void) imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info {
[self loadImage:[info objectForKey:UIImagePickerControllerOriginalImage]];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
// called for iPad
[popoverController dismissPopoverAnimated:YES];
}
}
else {
// called for iPhone and tried each of the next 3 lines individually
[self dismissModalViewControllerAnimated:YES]; <== NOT WORKING
[self dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING
[picker dismissViewControllerAnimated:YES completion:nil]; <== ALSO NOT WORKING
}
[picker release];
}
I also noticed that it said dimissModelViewControllerAnimated has been deprecated and that instead I should use:
Use dismissViewControllerAnimated:completion: instead. But how would I use this? Thanks
Here is the code that presents the model view:
- (void) actionSheet:(UIActionSheet *)actionSheet didDismissWithButtonIndex:(NSInteger)buttonIndex {
switch (buttonIndex) {
case 0: { //photo library
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypePhotoLibrary]) {
UIImagePickerController *imagePicker = [[UIImagePickerController alloc] init];
imagePicker.delegate = self;
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad ) {
if ([popoverController isPopoverVisible]) {
[popoverController dismissPopoverAnimated:YES];
}
else {
popoverController = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
popoverController.delegate = self;
[popoverController presentPopoverFromRect:CGRectMake( 250, -50, 320, 480 )
inView:[self view]
permittedArrowDirections:UIPopoverArrowDirectionUp
animated:YES];
}
}
else { // for iPhone
[self presentModalViewController:imagePicker animated:TRUE];
}
} else {
UIAlertView *alertView = [[UIAlertView alloc] initWithTitle:#"Error" message:#"Photo library is empty or unavailable" delegate:self cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alertView show];
}
break;
}
case 1: //camera
dismissModalViewControllerAnimated:: was deprecated in iOS6. Use dismissViewControllerAnimated:completion: instead.
[self dismissViewControllerAnimated:YES completion:nil];
presentModalViewController, and dismissModalViewController depracated in iOS6
Try this,
[self.imagePicker dismissViewControllerAnimated:NO completion:nil];
and use
[self presentViewController:self.picker animated:YES completion:nil];
You can also use respondsToSelector to make the cases for iOS 5 and ios6.

Black screen appears, randomly after taking an image and tapping 'USE' in the UIImagePickerController

I have an app that's almost done and now while it was under QA, the QA engineer came across a random issue in which a black screen appears after tapping on USE in UIImagePickerController view. Further in didFinishPickingMediaWithInfo the image is being saved for future refrencing and is being shown in an UIImageView, I am also using camera overlay for adding a button to the UIImagePickerView and the max memory usage of the app doen't goes beyond 13 MB. The issue is not arising when switching to Camera roll mode from capture mode. Also in the same view iADs are being presented. Underneath is the code, to which the issue may concern, also images are being attached to get an idea of the issue. Any help would be greatly appreciated.
Thanks in advance.
(void) launchCamera
{
// Set up the camera\
CustomCameraView *cameraController = [[CustomCameraView alloc] init];
cameraController.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraController.delegate = self;
cameraController.showsCameraControls = YES;
cameraController.navigationBarHidden = YES;
cameraController.toolbarHidden = YES;
// overlay on top of camera lens view
UIButton *cameraRoll = [[UIButton alloc] initWithFrame:CGRectMake(15, 380, 40, 40)];
[cameraRoll setAlpha:0.0f];
[cameraRoll setBackgroundImage:[UIImage imageNamed:#"CamerRoll_New"] forState:UIControlStateNormal];
[cameraRoll addTarget:self action:#selector(switchToCameraRoll) forControlEvents:UIControlEventTouchUpInside];
cameraController.cameraOverlayView = cameraRoll;
[UIView beginAnimations:nil context:NULL];
[UIView setAnimationDelay:1.5f];
cameraRoll.alpha = 1.0f;
[UIView commitAnimations];
[self presentModalViewController:cameraController animated:YES];
}
-(void)switchToCameraRoll
{
DLog(#"Camera Roll");
[self dismissViewControllerAnimated:NO completion:^(void){ [self photoSourcePhotoAlbum];}];
}
-(void) photoSourcePhotoAlbum
{
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingMediaWithInfo:(NSDictionary *)info
{
[self.view addSubview:progressView];
timer = [NSTimer scheduledTimerWithTimeInterval:.017 target:self selector:#selector(progressChange) userInfo:nil repeats:YES];
[picker dismissModalViewControllerAnimated:YES];
[self performSelectorInBackground:#selector(saveImage:) withObject:info];
[self performSelector:#selector(navigateToEditView) withObject:nil afterDelay:2.1];
}
-(void)navigateToEditView
{
[self performSegueWithIdentifier:#"presentRDetailModalViewController" sender:self];
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController *)picker
{
if (picker.sourceType == UIImagePickerControllerSourceTypeSavedPhotosAlbum)
{
[picker dismissViewControllerAnimated:NO completion:^(void){ [self photoSourceCamera];}];
}
else
{
[picker dismissModalViewControllerAnimated:YES];
}
}
-(void)saveImage:(NSDictionary *)info
{
NSString *imageName = [[[DataStaging dataStaging] getGUID] stringByAppendingString:#".jpg"];
rImageName = imageName;
UIImage *rImage = [info objectForKey:#"UIImagePickerControllerOriginalImage"];
//Compress image
[[FileOperations fileOperations] PersistData:UIImageJPEGRepresentation(rImage, 0.4) name:imageName];
DLog(#"%#",[[FileOperations fileOperations] fetchPath:imageName]);
//Actual image taken
[[self rImageView] setImage:[info objectForKey:#"UIImagePickerControllerOriginalImage"]];
if ([rImageName length] == 0)
{
[[self rDetails] setHidden:YES];
[[self trashRImage] setHidden:YES];
}
else
{
[[self rDetails] setHidden:NO];
[[self trashRImage] setHidden:NO];
}
[progressView removeFromSuperview];
}
}
Make sure you don't call presentModalViewController:animated: twice before dismissModalViewControllerAnimated:
It helped in my case.
- (void)showImagePickerForSourceType:(UIImagePickerControllerSourceType)sourceType
{
if (_imagePickerController!=nil || _imagePopoverController!=nil) {
return;
}
_imagePickerController = [[[UIImagePickerController alloc] init] autorelease];
_imagePickerController.modalPresentationStyle = UIModalPresentationCurrentContext;
_imagePickerController.sourceType = sourceType;
_imagePickerController.delegate = self;
switch (sourceType) {
case UIImagePickerControllerSourceTypeCamera:
_imagePickerController.showsCameraControls = YES;
[self presentViewController:_imagePickerController animated:YES completion:nil];
break;
default:
_imagePopoverController = [[UIPopoverController alloc] initWithContentViewController:_imagePickerController];
_imagePopoverController.delegate = self;
CGRect rect = [[UIScreen mainScreen] bounds];
rect.origin.y = rect.size.height - 70.0;
rect.size.height -= rect.origin.y;
[_imagePopoverController presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionDown animated:YES];
break;
}
}
- (void)imagePickerControllerDidCancel:(UIImagePickerController*)picker
{
[_imagePopoverController dismissPopoverAnimated:YES];
_imagePopoverController = nil;
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
_imagePickerController = nil;
}
- (void)imagePickerController:(UIImagePickerController*)picker didFinishPickingMediaWithInfo:(NSDictionary*)info
{
UIImageWriteToSavedPhotosAlbum([info objectForKey:UIImagePickerControllerOriginalImage],nil,nil,nil);
_currentImage = [info objectForKey:UIImagePickerControllerOriginalImage];
[_imagePopoverController dismissPopoverAnimated:YES];
_imagePopoverController = nil;
[_imagePickerController dismissViewControllerAnimated:YES completion:nil];
_imagePickerController = nil;
}

Iphone web view during use of Camera

Is it possible to open webview during use of camera in app.if it is possible plz let me know.
You could try:
- (BOOL)startCameraPickerFromViewController:(UIViewController*)controller usingDelegate:(id<UIImagePickerControllerDelegate>)delegateObject
{
//NSLog(#"008 ::Create Postcard :: start photo camera");
if ((![UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]) || (delegateObject == nil) || (controller == nil)) {
return NO;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
UIView *overlay = [[UIView alloc]initWithFrame:CGRectMake(x, y, w, h)];
// overlay.transform = CGAffineTransformMakeRotation(M_PI / 2.0);
// overlay.backgroundColor = [UIColor redColor];
{create your webview here}
[overlay addSubview:webview];
[webview release];
[picker.cameraOverlayView = overlay;
[controller presentModalViewController:picker animated:YES];
return YES;
}
If you have enough recources on the phone it might could work i guess

How to reduce the crop image box size in iphone?

In my application I m using UIImagePickerControllerCropRect to crop the image but I want to reduce the size of that cropping box of iphone which comes automatically so that my image crop to its perfect size which I want. I'm using the following code for that:
-(IBAction) getPhoto:(id) sender {
UIImagePickerController * picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
if((UIButton *) sender == choosePhotoBtn) {
picker.sourceType = UIImagePickerControllerSourceTypeSavedPhotosAlbum;
picker.allowsImageEditing = YES;
} else {
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
}
[self presentModalViewController:picker animated:YES];
}
- (void)imagePickerController:(UIImagePickerController *)picker didFinishPickingImage:(UIImage *)image editingInfo:(NSDictionary *)editingInfo {
[picker dismissModalViewControllerAnimated:YES];
imageView.image = image;
CGSize size = [imageView.image size];
CGRect cropRect = CGRectMake(0.0, 0.0, size.width, size.height);
NSLog(#"Original image size = (%f, %f)", size.width, size.height);
NSValue *cropRectValue = [editingInfo objectForKey:#"UIImagePickerControllerCropRect"];
cropRect = [cropRectValue CGRectValue];
UIImageWriteToSavedPhotosAlbum(imageView.image, self, nil, nil);
}