Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

customView 内部使用自动布局时 有问题 #49

Closed
ipad4 opened this issue Mar 21, 2019 · 3 comments
Closed

customView 内部使用自动布局时 有问题 #49

ipad4 opened this issue Mar 21, 2019 · 3 comments

Comments

@ipad4
Copy link

ipad4 commented Mar 21, 2019

customView 内部使用自动布局时,最后展示的界面中,customView的高度为0

@lixiang1994
Copy link
Owner

可以发一些相关代码吗?

@ipad4
Copy link
Author

ipad4 commented Mar 22, 2019

customView的宽度和高度是由其子控件撑起来的,后来看了你的源码布局自定视图的部分,发现是根据customView的frame来设置的,我就做了相关的修改

        LEECustomView *custom = (LEECustomView *)item;
        
        CGRect viewFrame = custom.view.frame;
        
        if (custom.isAutoWidth) {
            
            custom.positionType = LEECustomViewPositionTypeCenter;
            
            viewFrame.size.width = alertViewMaxWidth - self.config.modelHeaderInsets.left - custom.item.insets.left - self.config.modelHeaderInsets.right - custom.item.insets.right;
            
            CGSize fittingSize = UILayoutFittingCompressedSize;
            fittingSize.width = viewFrame.size.width;
            CGSize selfSize = [custom.view systemLayoutSizeFittingSize:fittingSize
                                  withHorizontalFittingPriority:UILayoutPriorityRequired
                                        verticalFittingPriority:UILayoutPriorityFittingSizeLevel];
                            
            viewFrame.size.height = selfSize.height;
        }

@lixiang1994
Copy link
Owner

你在添加前调用一下layoutIfNeeded这个方法呢?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants