How the prevent the popover from hiding with status bar in iOS6 - ios

I have a popover, which is presented from the code:
CGPoint screenPoint = [self.mapView screenPoint: self.selectedObject.pointCoordinate];
CGRect rect = CGRectMake(screenPoint.x, screenPoint.y, 1, 1);
[self.detailViewPopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
As u can see on the screenshot - the popover is hiding by the status bar - is it possible the exclude the status bar frame from the area where popover should be displayed?
The content size for view in popover looks like this:
self.contentSizeForViewInPopover = CGSizeMake (320, self.view.frame.size.height - 100);

You reset the UIPopoverArrowDirectionUp to UIPopoverArrowDirectionAny
[self.listViewPopover presentPopoverFromRect:rect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Related

popover size issue with ios 7.0.X, its not getting while loading popover

My popover is not getting properly sized while presenting with ios 7.03.
I'm Trying like
{
...
ClassObj *mail = [...];
[mail.view setFrame:CGRectMake(0, 0, 320, 216)];
[mail setContentSizeForViewInPopover:CGSizeMake(320,256)];
[refinePopover presentPopoverFromRect:sender.frame inView:[sender superview]
permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[mail setContentSizeForViewInPopover:CGSizeMake(320,256)];
...
}
And in ClassObj class i'm setting frame and size in viewwill/didApear method
{
[self setContentSizeForViewInPopover:CGSizeMake(320,256)];
[self.view setFrame:CGRectMake(0, 0, 320, 216)];
}
I'm plying more on this please let me know if you have any suggestion, Thanks in Advance. :)
You create a property of UIPopOverController Object in your ClassObj
and then assign that popoverController from that class where you are creating Your actual popover.
mail.popoverController = refinePopover;
now in your ClassObj in viewwill/didApear method add this code with 0.1 delay.
[popoverController setPopoverContentSize:CGSizeMake(320, 256)];
hope this will help you.

Can't make modal view appear right in the center of the screen on iPad iOS6

I have a problem with modalviewcontrollers that I want to represent on iPad screen. If I leave the size as it is, then it's all centred fine. But I have very few info on these views, so I need to resize them.
So, when I resize them, I can't force them to appear in the middle of the screen. Even if I manage to center one of them in one orientation, it's messed up in other one.
Here is my current code:
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:acvc];
[nav setModalPresentationStyle:UIModalPresentationFormSheet];
[nav setModalTransitionStyle: UIModalTransitionStyleCoverVertical];
[[acvc view] setBackgroundColor:[UIColor colorWithPatternImage:[UIImage imageNamed:#"main_bg.jpg"]]];
[self presentViewController:nav animated:YES completion:nil];
nav.view.superview.frame = CGRectMake(self.view.bounds.size.width/2 + 175, self.view.bounds.size.height/2 - 125, 350, 250);
// nav.view.superview.center = self.view.window.center;
Would appreciate any help, thank you.
Here's a method that works on iOS7 as well as iOS6 and iOS5 and still allows you to use UIModalTransitionStyleCoverVertical:
-(void)presentController:(UIViewController*)controller fromRootController:(UIViewController*)rootController withSize:(CGSize)size
{
UINavigationController* nav = [[UINavigationController alloc] initWithRootViewController:controller];
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nav.modalPresentationStyle = UIModalPresentationFormSheet;
[rootController presentModalViewController:nav animated:YES];
if ([[[UIDevice currentDevice] systemVersion] floatValue] >= 7.0)
{
nav.view.superview.backgroundColor = [UIColor clearColor];
nav.view.bounds = CGRectMake(0, 0, size.width, size.height);
}
else
{
nav.view.superview.bounds = CGRectMake(0, 0, size.width, size.height);
}
}
Change your last line to the following:
nav.view.superview.bounds = CGRectMake(0, 0, 350, 250);
Stopped working in iOS7, unfortunately.
Only changing ModalTransitionStyle to Dissolve solves the problem. Maybe it's a bug in iOS 7...
in ios 7 you can use :
- (void)viewWillLayoutSubviews
{
[super viewWillLayoutSubviews];
self.view.superview.bounds = CGRectMake(0, 0, width, height);
}
it works.

What is the correct way of resizing a modal navigation controller presented with UIModalPresentationFormSheet when showing a keyboard?

I'm presenting the navigation controller with this code (in the base class of the view controller being presented):
-(void)presentInNavigationControllerWithViewController:(UIViewController*)viewController
{
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:self];
nav.modalPresentationStyle = UIModalPresentationFormSheet;
nav.modalTransitionStyle = UIModalTransitionStyleCoverVertical;
nav.view.autoresizingMask = UIViewAnimationTransitionNone;
[viewController presentModalViewController:nav animated:YES];
CGRect rect = self.finalRect; /*desired size +44 height*/
CGRect windowRect = [self.view.window convertRect:self.view.window.frame toView:self.view];
rect.origin.y = (windowRect.size.height-rect.size.height)/2;
nav.view.superview.frame = rect;
}
To resize the view afterwards when the user clicks the text view:
// in viewDidLoad:
[[NSNotificationCenter defaultCenter] addObserver:self
selector:#selector(keyboardWillAppear:)
name:UIKeyboardWillShowNotification object:nil];
-(void)keyboardWillAppear:(NSNotification*)notification
{
UIView *view = self.navigationController.view.superview;
view.frame = CGRectMake(view.frame.origin.x + 200,
view.frame.origin.y,
view.frame.size.width-200,
view.frame.size.height);
}
In landscape mode, the result of view.frame.size.width-200 is decreasing the view's height by 200 (I'm because because the view's window is in portrait mode?). Another problem is that the shadow lags behind the navigation controller.
If I put the code in a animation : [UIView animateWithDuration:0.25 animations:^{, instead of a shadow, a gray rectangle lags behind instead.
What's the correct way of doing this ? (preferably with animation)

UIModalPresentationFormSheet resizing view

I am interested to know on how I can resize the view when using UIModalPresentationFormSheet of modalPresentationStyle, it looks like it has a fixed size so I was wondering if anyone out there did managed to manipulate the popup view from the sizing perspective.
So there is either UIModalPresentationFormSheet with a fixed view size or full views and I am after something in between.
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal;
[self presentModalViewController:targetController animated:YES];
// it is important to do this after presentModalViewController:animated:
targetController.view.superview.bounds = CGRectMake(0, 0, 200, 200);
You are able to adjust the frame of a modal view after presenting it:
Tested in iOS 5.1 - 6.1, using XCode 4.62
MyModalViewController *targetController = [[[MyModalViewController alloc] init] autorelease];
targetController.modalPresentationStyle = UIModalPresentationFormSheet;
targetController.modalTransitionStyle = UIModalTransitionStyleFlipHorizontal; //transition shouldn't matter
[self presentModalViewController:targetController animated:YES];
targetController.view.superview.frame = CGRectMake(0, 0, 200, 200);//it's important to do this after presentModalViewController
targetController.view.superview.center = GPointMake(roundf(self.view.center.x), roundf(self.view.center.y));//self.view assumes the base view is doing the launching, if not you might need self.view.superview.center etc.
Update The preferred iOS 6.0 view controller presentation method also works correctly:
- (void)presentViewController:(UIViewController *)viewControllerToPresent animated:(BOOL)flag completion:(void (^)(void))completion
In ios8 and earlier works:
AboutViewController * _aboutViewController = [[AboutViewController alloc] init];
_aboutViewController.modalPresentationStyle = UIModalPresentationFormSheet;
if(IS_IOS8)
{
_aboutViewController.preferredContentSize = CGSizeMake(300, 300);
}
[self presentViewController:_aboutViewController animated:YES completion:nil];
In AboutViewController.m
- (void)viewWillLayoutSubviews{
[super viewWillLayoutSubviews];
if(!IS_IOS8)
{
self.view.superview.bounds = CGRectMake(0, 0, 300, 300);
}
}
IS_IOS8
#define IS_IOS8 ([[[UIDevice currentDevice] systemVersion] floatValue] >= 8)
In iOS 8 you can also use UIPresentationController which gives you more customization options.
For iOS 8, simply implement the delegate method (CGSize)preferredContentSize on each view controller. It should resolve all the size issue.
Just to extent Fatos solution (great one)
If your are creating the view controller using a .xib file after the alloc initWithNibName you could store the view frame:
CGRect myFrame = targetController.view.frame;
...
targetController.view.superview.bounds = myFrame;
And then use it for superview.bounds, so the view's size in the .xib will be used and you could change the size more visually.
I put this code in the form sheet view controller:
-(void) viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
self.view.superview.bounds = CGRectMake(0, 0, 540, 500); // your size here
}
Note that the resizing occurs early enough that the the presentation animation looks correct.

Is there any way to present an UIPopover from an UITableView index?

I would like to present an UIPopover from an UITableView specific index.
Here's my code:
if (indexPath.row == 5) {
[tableView deselectRowAtIndexPath:indexPath animated:YES];
EnginesPopoverController *enginesPopoverController = [[EnginesPopoverController alloc] initWithNibName:#"EnginesPopoverController" bundle:nil];
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:enginesPopoverController];
self.popoverController = popover;
popoverController.delegate = self;
[popover release];
[enginesPopoverController release];
CGPoint point = {670, 600};
CGSize size = {450, 216};
[popoverController presentPopoverFromRect:CGRectMake(point.x, point.y, size.width, size.height) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
}
If I try to present the Popover from an UIButton it goes well...
Thanks!
This is what I do:
CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
CGRect popoverRect = CGRectMake(self.view.bounds.size.width - self.popoverController.popoverContentSize.width,
CGRectGetMidY(cellRect),
1.0, 1.0);
The x location I use places the popover on the right-hand side of the screen. This may not be what you want. To find the actual touch point, you can use gesture recognizers.
In return, please try to answer my related question: Popover's arrow to track an object in a scrollview
Manipulating David's code I arrived at this:
(my pop is called "storytPop")- my popover is from the toolbar and I wanted the next tableview to show to the right.
CGRect cellRect = [self.tableView rectForRowAtIndexPath:indexPath];
[self.storytPop presentPopoverFromRect:cellRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionLeft animated:YES];

Resources