uipopover issues while click and open the camera for ipad - ios

i have a popoverview issues while click and open the camera for ipad,i wrote code like that
-(IBAction)business_takephotobtnClicked // click the button show the popoverview
{
NSLog(#"business_takephotobtnClicked");
appdelegate.takePhoto=2;
popover = [[UIPopoverController alloc]
initWithContentViewController:imgclass];
popover.popoverContentSize = CGSizeMake(138,66);
[popover presentPopoverFromRect:popbtn_business.bounds inView:popbtn_business
permittedArrowDirections:UIPopoverArrowDirectionUp +
UIPopoverArrowDirectionLeft
animated:YES];
}
-(IBAction) takePhoto:(id)sender // to open the camera
{
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
self.contentSizeForViewInPopover=CGSizeMake(138,66);
UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:self.UIPicker animated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Camera is not available" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
}
before click the button the popover like that show
while click the take photo(Neem foto button).THE POPOVERVIEW SIZE IS AUTOMATICALLY EXTENTED like taht
But i need a same size popoverview while open the camera also
Thanks in Advance......

instead of using XIB use to create the camera view programatically and do like the following
-(IBAction)popbtn_Click:(id)sender
{
UIViewController* popoverContent = [[UIViewController alloc] init];
UIView* popoverView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 230, 180)];
popoverView.backgroundColor = [UIColor whiteColor];
take_btn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
[take_btn setTitle:#"Take" forState:UIControlStateNormal];
take_btn.frame=CGRectMake(2,2, 250, 60);
[take_btn addTarget:self action:#selector(take_btnclick:) forControlEvents:UIControlEventTouchUpInside];
[popoverView addSubview:take_btn];
}
-(void)take_btnclick:(id)sender
{
[popoverController dismissPopoverAnimated:YES];
if ([UIImagePickerController isSourceTypeAvailable:UIImagePickerControllerSourceTypeCamera])
{
UIPicker.sourceType = UIImagePickerControllerSourceTypeCamera;
[self presentModalViewController:self.UIPicker animated:YES];
[popoverController dismissPopoverAnimated:YES];
}
else {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle:nil message:#"Camera is not available" delegate:self cancelButtonTitle:#"Cancel" otherButtonTitles:nil];
[alert show];
[alert release];
}
if (popoverController != nil)
{
[popoverController dismissPopoverAnimated:YES];
}
}

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

Indicator within alert, indicator doesn't show up (resolved using UIAlertController)

I'm trying to follow the accepted solution from here on Xcode 6.3.2 but the indicator refuses to show up or I can't see it on my iPhone 6 plus for some reason. No error messages, the alert with the title, etc shows up and empty space.
What am I doing wrong? The alert is triggered after the connect button on the app is pressed...
UIAlertView *alertWithInd;
UIActivityIndicatorView *alertInd;
alertWithInd = [[UIAlertView alloc] initWithTitle:#"Connecting..." message:#"Please wait...\n\n\n\n\n\n\n\n\n" delegate:self cancelButtonTitle:nil otherButtonTitles:nil];
alertInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
alertInd.frame=CGRectMake(0, 20, 270, 100);
[alertInd startAnimating];
[alertWithInd addSubview:alertInd];
[alertWithInd show];
After doing some further research and for anyone else interested in finding the solution in one spot (as there are parts in many other posts) I post the code that uses an UIAlertController (instead of a UIAlert), has an indicator and also the code for dismissal without the need for a button to be pressed.
UIAlertController *alertController = [UIAlertController
alertControllerWithTitle:#"Connecting"
message:#"Please wait...\n\n"
preferredStyle:UIAlertControllerStyleAlert];
UIActivityIndicatorView *alertInd = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
alertInd.frame=CGRectMake(0, 40, 270, 100);
[alertInd startAnimating];
[alertController.view addSubview:alertInd];
id rootViewController=[UIApplication sharedApplication].delegate.window.rootViewController;
if([rootViewController isKindOfClass:[UINavigationController class]])
{
rootViewController=[((UINavigationController *)rootViewController).viewControllers objectAtIndex:0];
}
[rootViewController presentViewController:alertController animated:YES completion:nil];
// to dismiss the alert with no button use:
[alertController dismissViewControllerAnimated:YES completion:nil];
from the docs
Subclassing Notes
The UIAlertView class is intended to be used as-is and does not
support subclassing. The view hierarchy for this class is private and
must not be modified.
I was faced same issue in my one of project . I have resolved this in this way -
Define below in .h file
#property (strong, nonatomic) UIAlertView *alertViewProcessing;
.m file -
-(void)processing
{
self.alertViewProcessing = [[UIAlertView alloc] initWithTitle:#"Requesting...." message:nil delegate:nil cancelButtonTitle:nil otherButtonTitles: nil];
UIActivityIndicatorView *indicator = [[UIActivityIndicatorView alloc] initWithActivityIndicatorStyle:UIActivityIndicatorViewStyleGray];
[indicator startAnimating];
if (SYSTEM_VERSION_GREATER_THAN_OR_EQUAL_TO(#"8.0"))
{
UIView *view = [[UIView alloc] initWithFrame:CGRectMake(0.0, 0.0, 40.0, 40.0)];
view.backgroundColor =[UIColor clearColor];
indicator.frame = CGRectMake(120.0, 0.0, 20.0, 20.0 );
[view addSubview:indicator];
[self.alertViewProcessing setValue:view forKey:#"accessoryView"];
}
else
{
[self.alertViewProcessing setValue:indicator forKey:#"accessoryView"];
}
[self.alertViewProcessing show];
}

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.

UIPopover appearing from wrong button

I have an app which takes an image from existing library, or new from camera.
On the iPad, when I press the 'from library' button the popover appears (correctly) above the button from which it was pressed, however when I press the 'take photo' from the camera button, the camera controller appears over the 'from library' button also... I need this to appear over the 'take photo' button otherwise it looks a bit strange!
here is the code used;
- (void)pickImageFromLibrary: (id)sender
{
[Flurry logEvent: #"PickImage"];
[self openImagePickerWithSourceType: UIImagePickerControllerSourceTypePhotoLibrary];
}
- (void)takePicture: (id)sender
{
[Flurry logEvent: #"TakeImage"];
[self openImagePickerWithSourceType: UIImagePickerControllerSourceTypeCamera];
}
- (void)openImagePickerWithSourceType: (UIImagePickerControllerSourceType)sourceType
{
if ( ![UIImagePickerController isSourceTypeAvailable: sourceType] ) {
UIAlertView *alert = [[UIAlertView alloc] initWithTitle: NSLocalizedString( #"Error", #"" )
message: NSLocalizedString( #"We are sorry, but this functionality is not available at your device.", #"No camera eror" )
delegate: nil
cancelButtonTitle: NSLocalizedString( #"Dismiss", #"")
otherButtonTitles: nil];
[alert show];
return;
}
UIImagePickerController *picker = [[UIImagePickerController alloc] init];
picker.delegate = self;
picker.sourceType = sourceType;
self.isCameraShown = YES;
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
self.popover = [[UIPopoverController alloc] initWithContentViewController:(UIViewController *)picker];
CGRect takePhotoRect;
takePhotoRect.origin = self.view.frame.origin;
takePhotoRect.size.width = 1;
takePhotoRect.size.height = 1;
[self.popover setPopoverContentSize:CGSizeMake(320.0, 216.0)];
[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}else{
[self presentViewController:picker animated:YES completion:NULL ];
}
}
You are presenting the popover from the openLibraryButton.
[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
You need to add checking to see if the take photo or choose from library button was pressed, then show the popover for that button.
SUDO Code:
if (sourceType == UIImagePickerControllerSourceTypePhotoLibrary) {
[self.popover presentPopoverFromRect:_openLibraryButton.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
} else {
[self.popover presentPopoverFromRect:_takeFromCamera.frame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}

Cannot add a UIDatePicker to UIActionSheet

I want to add a UIDatePicker to a UIActionSheet, the code is below:
UIActionSheet* actionSheet = [[UIActionSheet alloc] initWithTitle:#"DEMO" delegate:self cancelButtonTitle:#"Cancle" destructiveButtonTitle:nil otherButtonTitles:nil];
actionSheet = [[UIActionSheet alloc] initWithTitle:#"Ratings"
delegate:self
cancelButtonTitle:#"Cancel"
destructiveButtonTitle:nil
otherButtonTitles:nil];
UIDatePicker *pickerView = [[UIDatePicker alloc] init];
pickerView.datePickerMode = UIDatePickerModeDate;
[actionSheet addSubview:pickerView];
[actionSheet showInView:self.view];
[actionSheet sendSubviewToBack:pickerView];
[actionSheet showInView:self.view];
[actionSheet setBounds:CGRectMake(0,0,320, 500)];
CGRect pickerRect = pickerView.bounds;
pickerRect.origin.y = -100;
pickerView.bounds = pickerRect;
[pickerView release];
[actionSheet release];
The question is why this code cannot work in iPad mode while it is ok in iphone mode
I would try using EAActionSheetPicker. It handles that for you.

Resources