Giter Club home page Giter Club logo

Comments (4)

wujianbotju avatar wujianbotju commented on August 24, 2024 10

稍微调试了一下,问题的原因在于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];
}
  1. 回到正题,为什么iOS8崩溃,iOS9不崩溃:因为在iOS9会使用系统自带的UIStackView的实现,而在iOS8上会调用FDStackView的实现。
  2. 究竟为什么在iOS8上FDStackView崩溃:对FDStackView的子view调用removeFromSuperView,此view从subviews移除了,却并没有从self.arrangedSubviews中移除。导致计算FDStackView的intrinsicContentSize时,子view的superView为nil但却存在约束。
  3. 如何解决
if (IS_IOS9_OR_GREATER)
{
        //UIStackView的removeArrangedSubview方法只会将其从arrangedSubviews中移除,而xxx依然会显示在屏幕上,因此我们需要调用removeFromSuperview方法
        //更多详情请查看UIStackView的removeArrangedSubview方法说明
        [xxx removeFromSuperview];
}
else
{
        //FDStackView的removeArrangedSubview方法会主动调用[xxx removeFromSuperview];
        [fdStackView removeArrangedSubview:xxx];
}

from fdstackview.

wujianbotju avatar wujianbotju commented on August 24, 2024

我也遇到了同样的问题,请问您解决了吗?

from fdstackview.

WeeTom avatar WeeTom commented on August 24, 2024

没解决,放弃了。

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.

monkiyang avatar monkiyang commented on August 24, 2024

@wujianbotju 按你的方法解决了,谢谢!!

from fdstackview.

Related Issues (20)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.