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];
});
Related
ScrollsToTop is not working when UIVeiwController is presented from ios8 extension.
But it is working if we presented it from inside the app. Can anyone help? sample code is shared here.
UIScrollView * scrollview = [[UIScrollView alloc]initWithFrame:CGRectMake(0, 0, 320, 300) ];
[scrollview setContentSize:CGSizeMake(320, 800)];
scrollview.layer.borderWidth = 1.0;
scrollview.backgroundColor =[UIColor redColor];
UIImageView *imageView = [[UIImageView alloc] initWithImage:[UIImage imageNamed:#"slide1"]];
[scrollview addSubview:imageView];
scrollview.showsVerticalScrollIndicator =YES;
scrollview.scrollsToTop = YES;
scrollview.delegate = self;
UIViewController *a = [[UIViewController alloc] init];
a.view.backgroundColor = [UIColor greenColor];
[a.view addSubview:scrollview];
[self presentViewController:a animated:YES completion:^{
}];
I had same issues & resolved using code bellow.
Some change has done in xcode6. Try this code to make scrollview to top.
[self.ScrollView setContentOffset:CGPointMake(0.0, 0.0) animated:YES];
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.
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.
How to change the size width of UIImagePickerController on iPad? I can change the height so it is 700 but can't change width and it still 320.
My code.
UIImagePickerController* imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
imagePicker.delegate=self;
CGRect myRect = CGRectMake(imagePicker.view.frame.origin.x, imagePicker.view.frame.origin.y, 720, 700);
imagePicker.view.frame = myRect;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
myRect = CGRectMake(100, 880, 900, 900);
CGRect re2 = CGRectMake(0,0,800,800);
[self.popover setPopoverContentSize:re2.size];
[self.popover presentPopoverFromRect:[self.view bounds] inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover presentPopoverFromRect:myRect inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:re2.size];
I had your same problem and I solved with the UINavigationControllerDelegate, since the UIImagePickerView content for the PhotoLibrary is a navigatorController. When you select a row it changes ViewController and the size of the popover changes as well.
So, in your willShowViewController delegate just put:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated {
viewController.contentSizeForViewInPopover = CGSizeMake(800, 800);
}
This will prevent the resizing of the popover.
This simplified code worked fine for me:
UIImagePickerController* imagePicker=[[UIImagePickerController alloc]init];
imagePicker.sourceType = UIImagePickerControllerSourceTypePhotoLibrary;
self.popover = [[UIPopoverController alloc] initWithContentViewController:imagePicker];
[self.popover presentPopoverFromRect:CGRectMake(100, 880, 1, 1) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
[self.popover setPopoverContentSize:CGSizeMake(700, 700)];
iOS 9 and above.
Another way is it to use ContainerViewController and add UImagePickerViewController to ContainerViewController. overriding size in UINavigationControllerDelegate methods has its limits. (not possible to go down on height below 600pt)
_imagePicker = [[UIImagePickerController alloc] init];
_imagePicker.delegate = self;
_imagePicker.sourceType = UIImagePickerControllerSourceTypeCamera;
_imagePicker.preferredContentSize = CGSizeMake(320, 480);
UIViewController *containerViewController = [[UIViewController alloc] init];
containerViewController.preferredContentSize = _imagePicker.preferredContentSize;
[containerViewController addChildViewController:_imagePicker];
[containerViewController.view addSubview:_imagePicker.view];
[_imagePicker didMoveToParentViewController:containerViewController];
if (!_imagePickerPopover) {
//customize PopoverController, use your own
_imagePickerPopover = [[PopoverController alloc] init:cnt];
}
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.