equivalent [UIPopoverController setContentViewController:(UIViewController *) animated:(BOOL)]; for iOS8 - size

what's the proper way to set UIPopoverController size in iOS8
in iOS7 was
[UIPopoverController setContentViewController:(UIViewController *) animated:(BOOL)];
but now it doesn't work
thanks in advance
EDIT: Gonna put my piece of code here and both results (iOS7.1 and iOS8)
DetalleTarjetaVC *controller = [self.storyboard instantiateViewControllerWithIdentifier:#"DetalleTarjetaVC"];
UINavigationController *navController;
navController = [[UINavigationController alloc] initWithRootViewController:controller];
navController.toolbarHidden = FALSE;
navController.navigationBar.translucent = FALSE;
navController.toolbar.translucent = FALSE;
navController.navigationBar.barTintColor = UIColorFromRGBWithAlpha(toolbarTintColor, 0.95);
navController.navigationBar.barStyle = UIBarStyleBlack;
navController.toolbar.barTintColor = UIColorFromRGBWithAlpha(toolbarTintColor, 0.95);
navController.toolbar.barStyle = UIBarStyleBlack;
controller.view.backgroundColor = UIColorFromRGBWithAlpha(0XFFFFFF, 1);
tarjetasPopover = [[UIPopoverController alloc] initWithContentViewController:navController];
CGRect rect = button.frame;
CGPoint coord = [button convertPoint:button.frame.origin toView:self.tableView];
rect.origin.y = coord.y -20;
[tarjetasPopover setPopoverContentSize:CGSizeMake(530, 400) animated:YES];
[tarjetasPopover presentPopoverFromRect:rect
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionLeft
animated:YES];

there's something that may help you
int iOSVersion = [[[UIDevice currentDevice]systemVersion] intValue];
if (iOSVersion >= 8) {
controller.preferredContentSize = CGSizeMake(530, 312);
}
else{
[tarjetasPopover setPopoverContentSize:CGSizeMake(530, 400) animated:YES];
}
I reduced in 88.0 height for iOS8 since you have to consider the width of your toolbar and navigation controller (44px each) for getting same size

The method have not been replaced in iOS8. You just need to alloc an istance before, like that:
UIPopoverController *yourPopoverController = [[UIPopoverController alloc] init];
and then you can use:
[yourPopoverController setContentViewController:yourViewController animated:YES];
Or easily you can pass the viewController on UIPopoverController Init:
UIPopoverController *popoverController = [[UIPopoverController alloc] initWithContentViewController:yourViewController];
Hope it help.

Related

Shift to UIPopoverPresentationController

I want to create the same popover for my iPhone app with size GGrect of (320 100.0).
Here is my old code:
View * pk1 = [[View alloc] init];
UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:pk1];
pop = [[UIPopoverController alloc] initWithContentViewController:nav];
[pop setDelegate:self];
[pop presentPopoverFromRect:[self btnsavepart].frame inView:[self view] permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[nav release];
I using this codes but its doesn't change
nav.preferredContentSize = CGSizeMake(320, 100);
I can not change UIpopovercontriller with UIPopoverPresentationController.
How do I specify GGrect of (320 100.0)?
i thinks i can change only on horizontally but how can i do.
View *viewController = [[[View alloc] init] autorelease];
UINavigationController *navController = [[[UINavigationController alloc] initWithRootViewController:viewController] autorelease];
navController.modalPresentationStyle = UIModalPresentationPopover;
navController.popoverPresentationController.permittedArrowDirections = UIPopoverArrowDirectionUp;
navController.popoverPresentationController.sourceRect = btnsavepart.bounds;
navController.popoverPresentationController.sourceView = btnsavepart;
navController.popoverPresentationController.delegate = self;
[self presentViewController:navController animated:YES completion:nil];
i want the UIPopoverPresentationController not FullScreen form in iPhone
i adding this codes but i give the FullScreen view
- (UIModalPresentationStyle)adaptivePresentationStyleForPresentationController:(UIPresentationController *)controller
{
return NO;
}
I work with Xamarin but its same thing , to specify size of the popover in which you want to display your UIViewController, in the properties of your UIVIewController you have the PreferredContentSize property. There you specify the size.
I saw it somewhere here but forgot where.

iOS8 popovercontroller height issue

I have a UIPopovercontroller.
Presenting it using this way.
BackupPop *backupPop = [[BackupPop alloc] initWithNibName:nil bundle:[NSBundle mainBundle]];
backupPop.delegate = self;
backupPop.navigationItem.title = [Language get2:#"Backup"];
UINavigationController *navController = [[UINavigationController alloc] initWithRootViewController:backupPop];
assigningBackupRow = button.tag;
backupPopController = [[UIPopoverController alloc] initWithContentViewController:navController];
backupPopController.popoverContentSize = CGSizeMake(200, 150);
CGRect rect = CGRectMake(button.frame.origin.x, button.frame.origin.y + 20 + (button.tag - 30000) * 44, button.frame.size.width, button.frame.size.height);
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
In the UIPopovercontroller, I have a UITableView in viewdidload.
funcTable = [[UITableView alloc] initWithFrame:CGRectMake(0, 0, 200, 80) style:UITableViewStylePlain];
[funcTable setDelegate:self];
[funcTable setDataSource:self];
[funcTable setRowHeight:44];
[funcTable setBackgroundColor:[UIColor clearColor]];
[self.view addSubview:funcTable];
The problem in iOS8, although my UITableView is 80px in height, it shows up as 40px only.
The starting position of the UITableView is right, but the height is not. Now, I have to put 120px as height to all of the UITableView that is in UIPopoverController. No such issue in iOS7.
Guys, any idea? Thanks.
Try this
iOS 8 has new PopOverController called UIPopoverPresentationController
UIStoryboard *storyboard = [UIStoryboard storyboardWithName:#"Main" bundle:nil];
UINavigationController *navController = [storyboard instantiateViewControllerWithIdentifier:#"Terms_NC"];
navController.preferredContentSize = CGSizeMake(300, 290);
// Present the view controller using the popover style.
navController.modalPresentationStyle = UIModalPresentationPopover;
[self presentViewController:navController animated: YES completion: nil];
// Get the popover presentation controller and configure it.
UIPopoverPresentationController *presentationController =
[navController popoverPresentationController];
presentationController.permittedArrowDirections =0;
presentationController.sourceView = self.view;
presentationController.sourceRect = CGRectMake(100, 100, 300, 340);
i had the same problem. what i did was i explicitly set the size of tableview again just before i was presenting my popover.
[backupPop adjustFrame];
backupPopController.popoverContentSize = backupPop.view.frame.size;
[backupPopController presentPopoverFromRect:rect inView:backupTable permittedArrowDirections:UIPopoverArrowDirectionRight animated:YES];
and you can add a method in backupPop
- (void)adjustFrame {
CGRect frame = self.view.frame;
frame.size.height = 80
frame.size.width = 200;
self.view.frame = frame;
}
Lemme know if it helps.
May be its workaround set the content size after little delay.
dispatch_after(dispatch_time(DISPATCH_TIME_NOW, (int64_t)(0.01 * NSEC_PER_SEC)), dispatch_get_main_queue(), ^{
[self.popoverController setPopoverContentSize:CGSizeMake(300, 340) animated:YES];
});

how to change the width of the UIPickerView in objective C

how to change the width of the UIPickerView in objective C, I am using the following code,
tempFiled = Data;
[tempFiled resignFirstResponder];
CGSize sizeOfPopover = CGSizeMake(200, 200);
CGPoint positionOfPopover = CGPointMake(32, 325);
[popOverControllerWithPicker presentPopoverFromRect:CGRectMake(positionOfPopover.x, positionOfPopover.y+10, 500, sizeOfPopover.height)
inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
But when i am trying to change the width in CGSize sizeOfPopover = CGSizeMake(200, 200); its not changing, i want to reduce the size of the picker.
I had this problem and solved it this way:
- (void)viewWillAppear:(BOOL)animated
{
[super viewWillAppear:animated];
CGRect frame = bpsPicker.frame;
frame.size.width = 100; // width to be displayed on popover controller
bpsPicker.frame = frame;
}
Using ViewDidLoad() is too early to alter this value.
To be clear the viewWillAppear is in the UIViewController that is passed to the UIPopover (here called 'MyViewController.m').So,
self.myViewController = [[MyViewController alloc] initWithNibName:#"MyViewController" bundle:nil] ;
self.myViewController.delegate = self;
self.myViewController.contentSizeForViewInPopover = CGSizeMake(320, 360); // or whatever
self.myViewControllerPopover = [[UIPopoverController alloc] initWithContentViewController:self.myViewController] ;
[self.myViewControllerPopover presentPopoverFromBarButtonItem:self.myToolBarButton permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];

Black Bar in UIImagePicker on iPad - Only in Landscape Right Orientation

I am showing a UIImagePicker (itself in a UIView) via a UIPopOver. This works fine, however when the iPad is rotated onto its right side I get a strange black bar along the left hand side of the popover as per the image below. The cancel button is also partially off the right hand of the screen. This doesn't happen in any other orientation which is odd.
The code is also listed below. Can anyone suggest why I am getting this black bar ?
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[imagePickerController.view setFrame:containerController.view.frame];
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[containerController release];
}
For some strange reason, the view's frame does change in landscape right.
To come over this, set the frame after you present the popover (view code below).
That should do the trick.
imagePickerController = [[UIImagePickerController alloc] init];
imagePickerController.delegate = self;
imagePickerController.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
CGFloat width = CGRectGetWidth(self.view.bounds);
CGFloat height = CGRectGetHeight(self.view.bounds);
UIViewController *containerController = [[UIViewController alloc] init];
containerController.contentSizeForViewInPopover = CGSizeMake(width, height);
[containerController.view addSubview:imagePickerController.view];
if (UI_USER_INTERFACE_IDIOM() == UIUserInterfaceIdiomPad) {
Class cls = NSClassFromString(#"UIPopoverController");
if (cls != nil) {
popoverController = [[UIPopoverController alloc] initWithContentViewController:containerController];
[popoverController presentPopoverFromRect:selectedRect inView:self.view permittedArrowDirections:4 animated:YES];
[imagePickerController.view setFrame:containerController.view.frame];
[containerController release];
}
Also, in your controller, add this to reset the frames when the rotation occurs:
- (void)didRotateFromInterfaceOrientation:(UIInterfaceOrientation)fromInterfaceOrientation {
[imagePickerController.view setFrame:imagePickerController.view.superview.frame];
}
The above approach works with iOS 5 and above but on iOS 4 and prior it's not possible to add the UIImagePickerController as a subview and then show it. It always has to be presented as a ModalViewController.
Try this. Reposting one solution I found using [currentDevice endGeneratingDeviceOrientationNotifications]
UIImagePickerController *picker = [[[UIImagePickerController alloc] init] autorelease];
picker.sourceType = UIImagePickerControllerSourceTypeCamera;
picker.delegate = self;
// Display the camera.
[self presentModalViewController:picker animated:YES];
// Given by default your orientation is in landscape right already
while ([currentDevice isGeneratingDeviceOrientationNotifications])
[currentDevice endGeneratingDeviceOrientationNotifications];
Source: Disable rotation in UIImagePicker

Bottom half of UITabbar is not responding to clicks

I have created a UITabbar with 3 items and placed it on a UIScrollView
When I click the buttons of the tabbar they do not respond in the bottom half.
The upper area is working fine.
When clicking in the area just above the tabbar the tabs are also switched.
What can be wrong?
How can i correct this misalignment of the clickable button area?
In viewDidLoad:
[super viewDidLoad];
scroll.frame = CGRectMake(0, 20, 320, 460);
scroll.pagingEnabled = YES;
scroll.contentSize = CGSizeMake(320 * 2, 460);
scroll.showsHorizontalScrollIndicator = NO;
scroll.showsVerticalScrollIndicator = NO;
scroll.scrollsToTop = NO;
scroll.delegate = self;
scroll.pagingEnabled = YES;
viewNavController1 = [[viewNavController1 alloc] init];
ctrl = [[UITabBarController alloc] init];
ViewController1 *viewC1= [[ViewController1 alloc] initWithNibName:#"ViewController1" bundle:nil];
UINavigationController *control = [[UINavigationController alloc] initWithRootViewController:viewC1];
viewC1.title = #"Title1";
[viewC1 release];
ViewController2 *viewC2 = [[ViewController2 alloc] initWithNibName:#"ViewController2" bundle:nil];
UINavigationController *control2 = [[UINavigationController alloc] initWithRootViewController:viewC2];
viewC2.title = #"Title2";
[viewC2 release];
UINavigationController *control3 = [[UINavigationController alloc] init];
ViewController3 *viewC3 = [[ViewController3 alloc] initWithNibName:#"ViewController3" bundle:nil];
[control3 pushViewController:viewC3 animated:NO];
viewC3.title = #"Title3";
[viewC3 release];
[ctrl setViewControllers:[NSArray arrayWithObjects:control,control2,control3,nil]];
CGRect frame = scroll.frame;
frame.origin.x = frame.size.width * 0;
frame.origin.y = 0;
viewNavController1.view.frame = frame;
viewC4 = [[ViewController4 alloc] initWithNibName:#"ViewController4" bundle:nil];
[viewNavController1 pushViewController:viewC4 animated:NO];
[scroll addSubview:viewNavController1.view];
frame = scroll.frame;
frame.origin.x = frame.size.width * 1;
frame.origin.y = 0;
ctrl.view.frame = frame;
[scroll addSubview:ctrl.view];
[scroll scrollRectToVisible:CGRectMake(320, 0, 320, 460) animated:NO];
UITabBarItem *itm = [ctrl.tabBar.items objectAtIndex:0];
itm.image = [UIImage imageNamed:#"img1.png"];
itm = [ctrl.tabBar.items objectAtIndex:1];
itm.image = [UIImage imageNamed:#"img2.png"];
itm = [ctrl.tabBar.items objectAtIndex:2];
itm.image = [UIImage imageNamed:#"img3.png"];
[control release];
[control2 release];
[control3 release];
The problem was that the UITabbarController did not have its view added as the root view of the windows. Which it apparently assumes.
so I had to trick it using:
[vc setWantsFullScreenLayout:YES];
vc is the main ViewController holding the scrollview containing the UITabbarController.
See Offset on UIWindow addSubview for more explanations.