Comments (3)
@mixdesign There is no straight forward approach for this. But I did have such requirement to adjust the popup's height according to it's subviews. Here is what I did to achieve this:
- (void)loadContentView
{
CGFloat width = [UIScreen mainScreen].bounds.size.width * 3 / 4;
CGFloat height = 400;
width = width > 300 ? width : 300;
self.contentSizeInPopup = CGSizeMake(width, height);
UIView *wrapperView = [UIView new]; // This is for wrappering the _contentView, to avoid constraints conflict on iOS 8.0 and 8.1
_contentView = [UIView new];
[wrapperView addSubview:_contentView];
[_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(width, height));
}];
[_contentView setNeedsLayout];
[_contentView layoutIfNeeded];
[self contentViewDidLoad];
[_contentView setNeedsLayout];
[_contentView layoutIfNeeded];
UIView *bottomView = nil;
for (UIView *subview in _contentView.subviews) {
if (subview.frame.origin.y + subview.frame.size.height > bottomView.frame.origin.y + bottomView.frame.size.height) {
bottomView = subview;
}
}
if (bottomView.frame.origin.y + bottomView.frame.size.height < height) {
[_contentView mas_updateConstraints:^(MASConstraintMaker *make) {
make.size.mas_equalTo(CGSizeMake(width, bottomView.frame.origin.y + bottomView.frame.size.height));
}];
[_contentView setNeedsLayout];
[_contentView layoutIfNeeded];
}
self.contentSizeInPopup = _contentView.bounds.size;
[_contentView removeFromSuperview];
}
- (void)contentViewDidLoad
{
// For subclass overriding
}
- (void)viewDidLoad
{
[self loadContentView];
[super viewDidLoad];
[self.view addSubview:_contentView];
[_contentView mas_makeConstraints:^(MASConstraintMaker *make) {
make.top.and.left.equalTo(_contentView.superview);
}];
}
BTW, I'm using Masonry, if you are using "raw" auto constraint or other library, the idea should be the same.
from stpopup.
@kevin0571 thank you, it really helps.
Can't we somehow automate this approach?
from stpopup.
@mixdesign currently can't. Will try to figure it out, and make it as simple as possible.
from stpopup.
Related Issues (20)
- Set height Fit Contents
- 弹出时
- Source View in Background shifts downwards when calling Popup from Bottom HOT 2
- How to make the popup view respond to drag? HOT 1
- Version 1.8.4 introduced a breaking of layout for iPhones with SafeArea HOT 5
- Trying to use STPopup in app delegate HOT 3
- Popup View float down when trigger keyboard
- STPopup source code for Swift version HOT 1
- Can pop up fit full screen height and width
- Is there a way to not call viewWillAppear on the parent controller after dismissing the popup?
- Wrong tap due to UIKeyboardWillHideNotification
- crashing on iPhone 6 version 12.2
- 当控制器里面有个属性名也叫popupController时,就会崩溃
- Enable interaction with vc behind popup on present
- 模态下是没办法使用的吗?
- popupController?.dismiss后 原来的控制器做push 动画失效
- 大佬弹出键盘选择文字的时候就会崩溃到这行代码st_becomeFirstResponder,怎么解决?
- navigationBarHidden 设置状态的时候就会崩溃
- looking forward to
- Main Thread Checker: UI API called on a background thread: -[UIViewController parentViewController]
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. 📊📈🎉
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google ❤️ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from stpopup.