Comments (4)
稍微调试了一下,问题的原因在于FDStackView的代码实现和系统原生的UIStackView的实现不一致,而且FDStackView没有正确处理FDStackView子view的removeFromSuperView的调用。
系统原生的UIStackView的removeArrangedSubview方法的注释是这样的:
Removes the provided view from the stack’s array of arranged subviews.
This method removes the provided view from the stack’s arrangedSubviews array. The view’s position and size will no longer be managed by the stack view. However, this method does not remove the provided view from the stack’s subviews array; therefore, the view is still displayed as part of the view hierarchy.
To prevent the view from appearing on screen after calling the stack’s removeArrangedSubview: method, explicitly remove the view from the subviews array by calling the view’s removeFromSuperview method, or set the view’s hidden property to YES.
简单翻译下就是说:对UIStackView中的子view调用removeArrangedSubview方法,UIStackView只是不再管理此view的布局了,但是此view还是会存在于UIStackView的subviews中(且仍然会显示在屏幕上,我实际测试了一下确实是显示在屏幕的左上角的,当然可能不同的版本会有些许的差别),如果想要阻止此view的显示,对此view明确地调用removeFromSuperView或者将其hidden属性设为YES。
但我们看下FDStackView的removeArrangedSubview实现
- (void)removeArrangedSubview:(UIView *)view {
if (![self.mutableArrangedSubviews containsObject:view] || ![view isDescendantOfView:self]) {
return;
}
[self removeHiddenObserverForView:view];
[self.mutableArrangedSubviews removeObject:view];
[view removeFromSuperview]; //这儿明显和系统的实现有差别
[self.alignmentArrangement removeItem:view];
[self.distributionArrangement removeItem:view];
[self updateLayoutArrangements];
}
- 回到正题,为什么iOS8崩溃,iOS9不崩溃:因为在iOS9会使用系统自带的UIStackView的实现,而在iOS8上会调用FDStackView的实现。
- 究竟为什么在iOS8上FDStackView崩溃:对FDStackView的子view调用removeFromSuperView,此view从subviews移除了,却并没有从self.arrangedSubviews中移除。导致计算FDStackView的intrinsicContentSize时,子view的superView为nil但却存在约束。
- 如何解决:
if (IS_IOS9_OR_GREATER)
{
//UIStackView的removeArrangedSubview方法只会将其从arrangedSubviews中移除,而xxx依然会显示在屏幕上,因此我们需要调用removeFromSuperview方法
//更多详情请查看UIStackView的removeArrangedSubview方法说明
[xxx removeFromSuperview];
}
else
{
//FDStackView的removeArrangedSubview方法会主动调用[xxx removeFromSuperview];
[fdStackView removeArrangedSubview:xxx];
}
from fdstackview.
我也遇到了同样的问题,请问您解决了吗?
from fdstackview.
没解决,放弃了。
wujianbotju [email protected]于2016年11月15日周二 下午2:31写道:
我也遇到了同样的问题,请问您解决了吗?
—
You are receiving this because you authored the thread.
Reply to this email directly, view it on GitHub
#35 (comment),
or mute the thread
https://github.com/notifications/unsubscribe-auth/ABvhQYIhgwt7C-LGx6eMSrDZXPYYo8dsks5q-VHSgaJpZM4I6chS
.
from fdstackview.
@wujianbotju 按你的方法解决了,谢谢!!
from fdstackview.
Related Issues (20)
- 子类化UIStackView,在ios9一下将会失效 HOT 1
- Return nil if it's compiled as a dynamic framework HOT 5
- ios7进入页面直接crash。 HOT 1
- pod方式安装后,ios8 alloc后stackview为nil HOT 7
- use with one more stackview
- Terminating app due to uncaught exception 'NSInvalidUnarchiveOperationException', reason: 'Could not instantiate class named UIStoryboardShowSegueTemplate'
- UIStackView can't be used when the deployment target is lower than 9.0 and Cocoapods version is 1.1.0.rc3
- effected in simulator but not true device。 HOT 1
- Use with swift HOT 1
- removeArrangedSubviews和removeFromSuperView与UIStackView不兼容 HOT 1
- Use with swift3 crash
- iOS8 crash on:resetCanvasConnectionsEffect HOT 1
- 能通过审核么 HOT 1
- 能支持 Carthage 么
- 在iOS10上removeAllSubviews后,再调用addArrangedSubview Crash
- is only available on iOS 9.0 or newer 警告怎么消除
- 在ios8.2下使用 隐藏StatckView上视图时 会崩溃
- addArrangedSubview逻辑错误
- iOS11新增功能提供 HOT 1
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 fdstackview.