I am trying to figure out why this tableView is shifted across to the right, it appears in every view the app uses, yet the app itself displays fine, it's only when the tableView appears is everything shifted out of the screen.
I believe the initializing is here;
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"Lets load the frame");
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame: frame];
self.contentSizeForViewInPopover = CGSizeMake(320, 480);
m_mywork = nil;
dataArray = [LoadSessionController loadTableData:YES];
}
Here is the initializing from another class;
on iPad display is perfect.
- (void) ShowInitialMenu
{
InitialMenuController *MewMgrController = [[InitialMenuController alloc] initWithStyle:UITableViewStyleGrouped];
MewMgrController.delegate = self;
UINavigationController* navController = [[UINavigationController alloc] initWithRootViewController: MewMgrController];
if(![ColorSplashAppDelegate isiPad]){
[self presentViewController:navController animated:YES completion:nil];
}
else{
UIPopoverController* popover = [[UIPopoverController alloc] initWithContentViewController:navController];
popover.delegate = self;
[popover presentPopoverFromRect:CGRectMake(30.0, 940.0, 30.0, 480.0)
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionDown
animated:YES];
ColorSplashAppDelegate *appDelegate = [UIApplication sharedApplication].delegate;
appDelegate.popoverController = popover;
}
[navController release];
[MewMgrController release];
[self enableUserAction:YES];
}
Try This.
-(void)viewDidLayoutSubviews
{
CGRect frame = CGRectMake(0, 0, self.view.frame.size.width, self.view.frame.size.height);
[self.view setFrame: frame];
self.contentSizeForViewInPopover = CGSizeMake(320, 480);
m_mywork = nil;
}
Related
The popover's preferred size is only works if the height is greater than 320.
I have searched a lot to solve this issue. But didn't find any answer. Is there any minimum size that the popover should satisfy in iPad? If not, what i'm missing?
Code:
UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
controller = [[UINavigationController alloc] initWithRootViewController:viewController];
SMFormViewController *formViewController = (SMFormViewController *)controller.topViewController;
formViewController.modalPresentationStyle = UIModalPresentationPopover;
formViewController.preferredContentSize = CGSizeMake(375, 320);
popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popController.delegate = self;
popController.sourceView = tblDocDetails;
NSInteger section = [tblDocDetails numberOfSections] - 1;
CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);
[self presentViewController:controller animated:YES completion:nil];
Note:
I tried, adaptivePresentationStyleForPresentationController: & adaptivePresentationStyleForPresentationController: to return UIModalPresentationNone.
I tried the following:
- (void)viewDidLoad {
[super viewDidLoad];
self.view.backgroundColor = [UIColor whiteColor];
UIButton *btnOpen = [UIButton buttonWithType:UIButtonTypeCustom];
[btnOpen setFrame:CGRectMake(100, 100, 100, 44)];
[btnOpen setTitle:#"POP" forState:UIControlStateNormal];
[btnOpen setBackgroundColor:[UIColor grayColor]];
[btnOpen addTarget:self action:#selector(btnOpen:) forControlEvents:UIControlEventTouchUpInside];
[self.view addSubview:btnOpen];
}
- (void)btnOpen:(id)sender {
UIView *sourceView = (UIButton *)sender;
UIViewController *vc = [[UIViewController alloc] initWithNibName:nil bundle:nil];
vc.modalPresentationStyle = UIModalPresentationPopover;
vc.preferredContentSize = CGSizeMake(150, 150);
[self presentViewController:vc animated:YES completion:nil];
UIPopoverPresentationController *popVc = vc.popoverPresentationController;
popVc.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popVc.sourceView = sourceView;
popVc.sourceRect = sourceView.bounds;
}
and it resulted in this (iPad Air 2, iOS 11.2):
Here is a solution based on your example, I think your use of GCD to show the popover might be causing the issue...
UIViewController *viewController = [subStoryboard instantiateViewControllerWithIdentifier:SMFormViewControllerSBID];
controller = [[UINavigationController alloc] initWithRootViewController:viewController];
controller.modalPresentationStyle = UIModalPresentationPopover;
controller.preferredContentSize = CGSizeMake(375, 320);
[self presentViewController:controller animated:YES completion:nil];
popController = [controller popoverPresentationController];
popController.permittedArrowDirections = UIPopoverArrowDirectionLeft;
popController.delegate = self;
popController.sourceView = tblDocDetails;
NSInteger section = [tblDocDetails numberOfSections] - 1;
CGRect rectCustomLoc = [tblDocDetails rectForFooterInSection:section];
popController.sourceRect = CGRectMake(rectCustomLoc.origin.x, rectCustomLoc.origin.y, 130, rectCustomLoc.origin.y/2);
My popover sometimes doesn't visible, because of the sourceRect was incorrect.
Since I embedded ViewController in a Navigation Controller, preferredContentSize should set to Navigation Controller.
controller.preferredContentSize = CGSizeMake(375, 100);
& in ViewController:
self.navigationController.preferredContentSize = contentsize;
And Changed sourceRect to:
CGRect rectCustomLoc = [table rectForFooterInSection:section];
rectCustomLoc.size.width = sender.frame.size.width;
popController.sourceRect = rectCustomLoc;
I create the view programmatically for UITabBarController.
In ViewController.m
#interface ViewController ()
{
UITabBarController *tabBarController;
MainViewController *mainView;
GroupViewController *grpView;
}
-(id)init
{
self=[super init];
[self initControl];
return self;
}
-(void)initControl
{
}
- (void)viewDidLoad {
[super viewDidLoad];
NSLog(#"ViewController - viewDidLoad");
self.mainView=[[MainViewController alloc] init];
self.grpView=[[GroupViewController alloc] initWithNibName:#"GroupViewController" bundle:[NSBundle mainBundle]];
self.meView=[[MeViewController alloc] initWithNibName:#"MeViewController" bundle:[NSBundle mainBundle]];
UITabBarItem *tempItem=[[UITabBarItem alloc] initWithTitle:NSLocalizedString(#"Device", #"Device") image:[[UIImage imageNamed:#"device1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:1];
tempItem.selectedImage=[UIImage imageNamed:#"device"];
mainView.tabBarItem=tempItem;
tempItem.imageInsets = UIEdgeInsetsMake(0.0, 0, -0.0, 0);
tempItem=[[UITabBarItem alloc] initWithTitle:NSLocalizedString(#"Group", #"Group") image:[[UIImage imageNamed:#"group1"] imageWithRenderingMode:UIImageRenderingModeAlwaysOriginal] tag:2];
tempItem.selectedImage=[UIImage imageNamed:#"group1"];
grpView.tabBarItem=tempItem;
tempItem.imageInsets = UIEdgeInsetsMake(0.0, 0, -0.0, 0);
self.tabBarController= [[UITabBarController alloc] init];
NSMutableArray *controllers=[[NSMutableArray alloc] initWithCapacity:2];
[controllers addObject:self.mainView];
[controllers addObject:self.grpView];
self.tabBarController.viewControllers =controllers;
[self.view addSubview:self.tabBarController.view];
self.tabBarController.delegate=self;
}
It is work fine when the personal hotspot is off.
When I turn on the Hotspot and somebody connect to the iPhone , and than open the App. The view is out of the screen like the following screen shot when the personal hotspot is on.
How to solve the problem when the personal hotspot is turn on ?
Thanks in advance.
check this
add observer for status bar changed the length:
[[NSNotificationCenter defaultCenter] addObserver:self selector:#selector(StatusbarspaceHide:) name:UIApplicationWillEnterForegroundNotification object:nil];
action when status bar changed :
-(void)StatusbarspaceHide:(NSNotificationCenter *)notification{
[UIView animateWithDuration:0.35 animations:^{
// CGRect windowFrame = ((UINavigationController *)((UITabBarController *)self.window.rootViewController).viewControllers[0]).view.frame;
CGRect windowFrame = self.view.frame;
if (self.view.frame.origin.y > 20) {
windowFrame.origin.y = self.view.frame.size.height - 20 ;// old status bar frame is 20
}
self.view.frame = windowFrame;
}];
}
Using UIPopovercontroller below ios8.0 in iphone working fine with this code. But in ios8 it display white screen.
Code :
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
popOverController = [[UIPopoverController alloc] initWithContentViewController:pickerController];
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
CGRect ImageBtnFrame = [self.view convertRect:sender.frame fromView:self.view];
[popOverController presentPopoverFromRect:ImageBtnFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
Any alternative for ios8, need suggestion.
According to 2014 WWDC, in the 30 minute mark, the right answer is:
- (void) tapButton:(id) sender
{
MyViewControllerClass * vc = [[MyViewControllerClass alloc] init];
vc.modalPresentationStyle = UIModalPresentationPopover;
UIPopoverPresentationController * popOverController = vc.popoverPresentationController;
[popOverController setDelegate:self];
popOverController.sourceView = sender;
popOverController.sourceRect = ((UIButton*)sender).frame;
popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:vc
animated:YES
completion:nil];
}
Notice that the accepted answer has some problems like:
Not setting the modalPresentationStyle
Presenting the UIPopoverPresentationController * instead of the UIViewController
Try to use the new iOS 8 API for popovers.
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
UIPopoverPresentationController *popOverController = pickerController .popoverPresentationController;
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
popOverController.sourceView = self.view;
popOverController.sourceRect = sender.frame;
popOverController.permittedArrowDirections = UIPopoverArrowDirectionUp;
[self presentViewController:popOverController
animated:YES
completion:nil];
That will cause on iOS 8. So, I recommended to use following Github library.
https://github.com/skywinder/ActionSheetPicker-3.0 or you can write code base on iOS version.
if (OLDER_THAN_IOS_8) {
// Your regular code
pickerController = [[UIViewController alloc] init];
UIView *viewV = [[UIView alloc] initWithFrame:CGRectMake(0, 0, 150, 160)];
[viewV setBackgroundColor:[UIColor clearColor]];
popOverController = [[UIPopoverController alloc] initWithContentViewController:pickerController];
popOverController.popoverContentSize = CGSizeMake(150, 160);
[popOverController setDelegate:self];
CGRect ImageBtnFrame = [self.view convertRect:sender.frame fromView:self.view];
[popOverController presentPopoverFromRect:ImageBtnFrame inView:self.view permittedArrowDirections:UIPopoverArrowDirectionUp animated:YES];
} else {
// New Code that support iOS -8 using UIPopoverPresentationController
// Checkout #AndreasZ answer for the same
}
How to add UIImagePickerViewController as a subview in ipad.
in iphone i used like this this working fine
self.pick = [[UIImagePickerController alloc]init];
pick.delegate = self;
pick.sourceType = UIImagePickerControllerSourceTypeCamera;
pick.sourceType = UIImagePickerControllerCameraDeviceFront;
pick.showsCameraControls = NO;
CGRect rect = CGRectMake(0, 0, 200, 250);
pick.view.frame = rect;
UIView *cameraView = [[UIView alloc] initWithFrame:CGRectMake(50, 50, 200, 200)];
[cameraView setBackgroundColor:[UIColor greenColor]];
[cameraView addSubview:pick.view];
[self.view addSubview:cameraView];
[pick viewWillAppear:YES];
[pick viewDidAppear:YES];
[pick release];
but same way i pad is not working. ipad is getting full view when camera is open.
i don't want to use popoverview controller.
pls help me?
UIImagePickerController must be presented with UIPopoverController on iPad.
if ([[UIDevice currentDevice] userInterfaceIdiom] == UIUserInterfaceIdiomPad) {
UIPopoverController *popover = [[UIPopoverController alloc] initWithContentViewController:picker];
[popover presentPopoverFromRect:self.selectedImageView.bounds inView:self.selectedImageView permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];
self.popOver = popover;
} else {
[self presentModalViewController:picker animated:YES];
}
How to add the UIView into UIPopoverViewController
-(void) buttonAction:(id)sender {
//build our custom popover view
UIViewController* popoverContent = [[UIViewController alloc]
init];
UIView* popoverView = [[UIView alloc]
initWithFrame:CGRectMake(0, 0, 200, 300)];
popoverView.backgroundColor = [UIColor whiteColor];
popoverContent.view = popoverView;
//resize the popover view shown
//in the current view to the view's size
popoverContent.contentSizeForViewInPopover =
CGSizeMake(200, 300);
//create a popover controller
self.popoverController = [[UIPopoverController alloc]
initWithContentViewController:popoverContent];
//present the popover view non-modal with a
//refrence to the button pressed within the current view
[self.popoverController presentPopoverFromRect:popoverButton.frame
inView:self.view
permittedArrowDirections:UIPopoverArrowDirectionAny
animated:YES];
//release the popover content
[popoverView release];
[popoverContent release];
}
This will add the view to your UIPopoverViewController
You can check the following link below to get some idea as to how to do this
Are there examples of how to use UIPopoverController on iOS?
Try the below Code:
if (mycontroller == nil) {
MyController * viewController = [[MyController alloc] initWithNibName:#"ControllerView" bundle:nil];
mycontroller = viewController;
PopoverController = [[UIPopoverController alloc] initWithContentViewController:self.mycontroller];
PopoverController.delegate = self;
}
[PopoverController presentPopoverFromRect:CGRectMake(260, 120, 10, 10) inView:self.view permittedArrowDirections:UIPopoverArrowDirectionAny animated:YES];