UIImagePickerController Above UIAlertView - ios

I'm developing an Application in which I need the UIAlertView to be present in the background while UIImagePickerController is presenting the camera. Currently, the UIAlertView is displayed as a superview (above the camera) when camera controller is presented.
Ideas are appreciated.

AlertViews are added to the window and not the controller. They will always be on the top. you can present the picker in an alertview to overlap it.
you can use this library
https://github.com/wimagguc/ios-custom-alertview
UIImagePickerController *cameraView = [[UIImagePickerController alloc] init];
cameraView.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraView.showsCameraControls = NO;
CustomIOSAlertView *alertView = [[CustomIOSAlertView alloc] init];
UIView *container = [[UIView alloc] initWithFrame:CGRectMake(0, 0, screen.size.width, screen.size.height)];
[container addSubview:cameraView.view];
container.subviews.lastObject.center = CGPointMake(container.subviews.lastObject.center.x, container.center.y);
[alertView setContainerView:container];
[alertView setDelegate:self];
// Display the dialog
[cameraView viewWillAppear:YES]; // trickery to make it show
[cameraView viewDidAppear:YES];
[alertView show];

You can show alertView and then present ImagepickerController. So when you dissmiss that imagePickerController you alertView will there on viewController.

Related

How to dismiss the UIAlertview on the click of UIViewController or on the UIScrollView in objective c

I am new in iOS and I am facing the problem regarding to dismiss the UIAlertview. I am showing Image in UIAlertview and I am using long press gesture to call the alertview. My code is like this
ImageName.userInteractionEnabled=YES;
UILongPressGestureRecognizer *longpressgestureRecognizer = [[UILongPressGestureRecognizer alloc] init];
[longpressgestureRecognizer addTarget:self action:#selector(imgLongPressed:)];
longpressgestureRecognizer.delegate = self;
[ImageName addGestureRecognizer: longpressgestureRecognizer];
- (void) imgLongPressed:(UILongPressGestureRecognizer*)sender
{
UIImageView *imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0, 0, 200, 282)];
UIImage *wonImage = ImageName.image;
imageView.contentMode=UIViewContentModeCenter;
[imageView setImage:wonImage];
alertView = [[UIAlertView alloc] initWithTitle:#""
message:#""
delegate:self
cancelButtonTitle:nil
otherButtonTitles:#"OK", nil];
//check if os version is 7 or above
if (floor(NSFoundationVersionNumber) > NSFoundationVersionNumber_iOS_6_1) {
[alertView setValue:imageView forKey:#"accessoryView"];
}else{
[alertView addSubview:imageView];
}
[alertView show];
[self performSelector:#selector(dismiss:) withObject:alertView afterDelay:1.0];
}
-(void)dismiss:(UIAlertView*)alert
{
[alert dismissWithClickedButtonIndex:-1 animated:YES];
}
This code give me output like this Image
I need to dismiss the UIAlertview on the touch of UIViewController or UIScrollView.
UIAlertView is depreciated. It is generally not advised to use depreciated elements since they might cause some problems with latest versions of iOS. For the given functionality, I think it's better to use thirdparty AlertViews like this one: https://cocoapods.org/pods/SCLAlertView-Objective-C

UIImagePickerController doesn't fit into the window when presented

I am trying to develop a simple application which is going to work with the photos the user takes. By following https://developer.apple.com/library/ios/documentation/AudioVideo/Conceptual/CameraAndPhotoLib_TopicsForIOS/Articles/TakingPicturesAndMovies.html I am using a UIImagePickerController in order to take the snapshot. I have a basic application with a single, empty view controller and in the viewDidAppear method I do the following:
- (void)viewDidAppear:(BOOL)animated
{
if ([UIImagePickerController isSourceTypeAvailable:
UIImagePickerControllerSourceTypeCamera] == NO)
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: #"Error" message: #"Can't use the camera!" delegate: nil cancelButtonTitle:#"OK" otherButtonTitles:nil];
[alert show];
return;
}
UIImagePickerController *cameraUI = [[UIImagePickerController alloc] init];
cameraUI.sourceType = UIImagePickerControllerSourceTypeCamera;
cameraUI.allowsEditing = NO;
cameraUI.delegate = self;
[self presentViewController: cameraUI animated: YES completion:NULL];
}
The resulting view becomes something like:
As you can see the front-rear camera change button doesn't show completely and the UIImagePickerController does not fit into the screen. Should I additionally resize before presenting or am I doing something incorrectly?

UIImagePickerController in subview >not fullscreen

I'm trying to add UIImagePickerController into my rootviewcontroller as a subview, so that the camera is displayed within the main app area, not as an overlay.
Here is my code:
-(void)cameraSetup{
CGRect bottomBarFrame = CGRectMake(0, self.view.frame.size.height-UA_BOTTOM_BAR_HEIGHT, self.view.frame.size.width, UA_BOTTOM_BAR_HEIGHT);
self.bottomNavBar = [[BottomNavBar alloc] initWithFrame:bottomBarFrame leftIcon:UA_ICON_PHOTOLIBRARY withFrame:CGRectMake(0, 0, 45, 22.5) centerIcon:UA_ICON_TAKE_PHOTO withFrame:CGRectMake(0, 0, 90, 45)];
//create a new image picker instance
picker = [[UIImagePickerController alloc]init];
picker.delegate = self;
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera]){
//set source to video!
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
//hide all controls
picker.showsCameraControls = NO;
picker.navigationBarHidden = NO;
picker.toolbarHidden = YES;
picker.editing = NO;
//make the video preview full size
//picker.wantsFullScreenLayout = YES;
picker.cameraViewTransform = CGAffineTransformScale(picker.cameraViewTransform,1, 1);
[picker.view addSubview:self.bottomNavBar];
picker.view.frame=CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height-(UA_TOP_WHITE+UA_TOP_WHITE-bottomBarFrame.size.height));
[self.view addSubview:picker.view];
[picker viewWillAppear:YES];
[picker viewDidAppear:YES];
}else{
UIAlertView *alert = [[UIAlertView alloc]initWithTitle:#"Test Text" message:#"Camera is Not Availble" delegate:self cancelButtonTitle:#"ok" otherButtonTitles:nil];
[alert show];
}
}
even though I'm setting the frame of the picker not to be full-screen it always appears full-screen. is there any way to get rid of that behavior? or is there another option to display my BottomNavBar on top of the picker?
UIImagePickerController is intended for use when an application requires access to system resources, like the camera or even the users photo library. As they UIImagePickerController enables system access in a controlled manner, it is obvious you cannot customize it.

UIReferenceLibraryViewController in a popover

I have this portion of code to pull up the dictionary if a word is searched:
- (IBAction)searchButtonPressed:(id)sender
{
NSString *searchTerm = self.searchTextField.text;
if([UIReferenceLibraryViewController dictionaryHasDefinitionForTerm:searchTerm])
{
UIReferenceLibraryViewController *referenceLibraryVC = [[UIReferenceLibraryViewController alloc] initWithTerm:searchTerm];
[self presentModalViewController:referenceLibraryVC animated:NO];
}
else
{
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:#"Word not found" message:#"no definition" delegate:nil cancelButtonTitle:#"OK" otherButtonTitles:nil, nil];
[alert show];
}
}
however, it only seems to work on the main view in the xib and covers the entier iPad screen. How can I get it so that it only opens up in a subview, just a portion of the screen?
Use a UIPopoverController, like it is used in native applications.
self.popover = [[UIPopoverController alloc] initWithContentViewController:referenceLibraryVC];
[self.popover presentPopoverFromRect:[sender frame] inView:[sender superview] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You will need to retain the popover controller until it is dismissed. Set the delegate and you can listen when it is dismissed so you can release it.

Shutter animation messed up when adding UIImagePickerController as subview

I'm adding UIImagePickerController as a subview of my UINavigationController which is inside a UIPopoverController.
Heres the code:
UIViewController *container = [[UIViewController alloc] init];
self.navigationBarHidden = YES;
camera = [[UIImagePickerController alloc] init];
camera.sourceType = UIImagePickerControllerSourceTypeCamera;
[container addChildViewController:camera];
[container.view setFrame:camera.view.frame];
[container.view addSubview:camera.view];
[self pushViewController:container animated:YES];
Everything looks great but the shutter animation. It seems to be off center, where the middle of the iris is actually hitting the top of the view.
How do I fix the shutter animation?

Resources