soberman / arspopover Goto Github PK
View Code? Open in Web Editor NEWUniversal popover for iPhone and iPad.
License: MIT License
Universal popover for iPhone and iPad.
License: MIT License
original code
[self presentViewController:popoverController animated:YES completion:^{
[popoverController insertContentIntoPopover:^(JKPopoverController *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
CGFloat originX = 0;
CGFloat originY = 0;
CGFloat width = popoverPresentedSize.width;
CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
CGRect frame = CGRectMake(originX, originY, width, height);
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
webView.scalesPageToFit = YES;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
[popover.view addSubview:webView];
}];
}];
But I dont want to use the block method ,so i changed code like this
[self presentViewController:popoverController animated:YES completion:^{
CGFloat presentationArrowHeight = 12.0;
CGFloat width = CGRectGetWidth(self.popoverPresentationController.frameOfPresentedViewInContainerView);
CGFloat height = CGRectGetHeight(self.popoverPresentationController.frameOfPresentedViewInContainerView);
CGSize popoverSize = CGSizeMake(width, height);
CGFloat originX = 0;
CGFloat originY = 0;
CGFloat webWidth = popoverSize.width;
CGFloat webHeight = popoverSize.height - presentationArrowHeight;
CGRect frame = CGRectMake(originX, originY, webWidth, webHeight);
UIWebView *webView = [[UIWebView alloc] initWithFrame:frame];
webView.scalesPageToFit = YES;
[webView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:@"https://google.com"]]];
[popoverController.view addSubview:webView];
Howevey, both of value of width & hight are 0 !
CGFloat width = CGRectGetWidth(self.popoverPresentationController.frameOfPresentedViewInContainerView);
CGFloat height = CGRectGetHeight(self.popoverPresentationController.frameOfPresentedViewInContainerView);
Could you help me ?
If I try to present the popover form a button in landscape on iPhone 6 Plus I get a UIModalPresentationFormSheet instead of a popover and the content is not loaded.
The issue is reproducible with the demo app if you enable landscape orientation and fix the autolayout constrains of the two buttons.
Presenting in landscape on iPhone 6 and lower works.
- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
[tableView deselectRowAtIndexPath:indexPath animated:YES];
ARSPopover *popoverController = [ARSPopover new];
popoverController.sourceView = [tableView cellForRowAtIndexPath:indexPath];
popoverController.sourceRect = [tableView rectForSection:indexPath.section];
popoverController.contentSize = CGSizeMake(200, 100);
popoverController.arrowDirection = UIPopoverArrowDirectionAny;
[self presentViewController:popoverController animated:YES completion:^{
[popoverController insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
CGFloat originX = 0;
CGFloat originY = 0;
CGFloat width = popoverPresentedSize.width;
CGFloat height = popoverPresentedSize.height - popoverArrowHeight;
CounterView *view = [CounterView new];
[popover.view addSubview:view];
}];
}];
return;
}
Hi! I'm having trouble dismissing it using those method. I tried to add tag on popoverController and inside the .insertContentIntoPopover and tried view.viewWithTag(calendar_tag)?.removeFromSuperview()
But it seems to be not working. Thanks!
When i'm setting the variable inside the class like this:
But if I'm setting it inside the showDatePickerPopover()
It's working fine. But the problem if i do that I can't call the closePopover()
method inside any function. Here's the video:
https://www.youtube.com/watch?v=5AGi-6cw8gw
Thanks!
How to dismiss popover? There is no property to dismiss the popover If I need to dismiss it after the UITableView Row selection inside popover.
I need to change popover size when it's shown. I know i can dismiss it without animation and show new one without animation but it leads to flickering and it looks bad.
Any idea on how to do it?
As a very simple sample I'm trying to display a multi-line UILabel in an ARSPopover using Auto Layout to break it into multiple lines and to ensure that the popover's content size fits within the screen:
ARSPopover *popover = [ARSPopover new];
popover.sourceView = sourceView;
popover.sourceRect = CGRectMake(CGRectGetMidX(sourceView.bounds), CGRectGetMaxY(sourceView.bounds), 0.0f, 0.0f);
// popover.contentSize = CGSizeMake(200.0f, 100.0f);
popover.arrowDirection = UIPopoverArrowDirectionUp;
[popover insertContentIntoPopover:^(ARSPopover *popover, CGSize popoverPresentedSize, CGFloat popoverArrowHeight) {
UILabel *label = [[UILabel alloc] init];
label.text = @"This is a tutorial view! Let's see if this works properly.";
label.numberOfLines = 0;
label.textAlignment = NSTextAlignmentLeft;
[label sizeToFit];
[popover.view addSubview:label];
[popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeLeft relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeLeftMargin multiplier:1.0f constant:0.0f]];
[popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeRight relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeRightMargin multiplier:1.0f constant:0.0f]];
[popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeTopMargin multiplier:1.0f constant:0.0f]];
[popover.view addConstraint:[NSLayoutConstraint constraintWithItem:label attribute:NSLayoutAttributeBottom relatedBy:NSLayoutRelationEqual toItem:popover.view attribute:NSLayoutAttributeBottomMargin multiplier:1.0f constant:0.0f]];
[popover.view setNeedsUpdateConstraints];
[popover.view layoutIfNeeded];
}];
[self presentViewController:popover animated:YES completion:nil];
However it doesn't seem like ARSPopover supports Auto Layout.
A declarative, efficient, and flexible JavaScript library for building user interfaces.
๐ Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
An Open Source Machine Learning Framework for Everyone
The Web framework for perfectionists with deadlines.
A PHP framework for web artisans
Bring data to life with SVG, Canvas and HTML. ๐๐๐
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
Some thing interesting about web. New door for the world.
A server is a program made to process requests and deliver data to clients.
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
Some thing interesting about visualization, use data art
Some thing interesting about game, make everyone happy.
We are working to build community through open source technology. NB: members must have two-factor auth.
Open source projects and samples from Microsoft.
Google โค๏ธ Open Source for everyone.
Alibaba Open Source for everyone
Data-Driven Documents codes.
China tencent open source team.