Skip to content
This repository has been archived by the owner on Feb 17, 2021. It is now read-only.

UIVisualEffectView not supported #172

Open
jiachenmu opened this issue Oct 30, 2017 · 2 comments
Open

UIVisualEffectView not supported #172

jiachenmu opened this issue Oct 30, 2017 · 2 comments

Comments

@jiachenmu
Copy link

jiachenmu commented Oct 30, 2017

like the kind of View.contenView
eg:

class BlurLayout: SizeLayout< UIVisualEffectView > {
   ..........
}

it will crash:

extension View {

    /**
     Similar to `addSubview()` except if `maintainCoordinates` is true, then the view's frame
     will be adjusted so that its absolute position on the screen does not change.
     */
    fileprivate func addSubview(_ view: View, maintainCoordinates: Bool) {
        if maintainCoordinates {
            let frame = view.convertToAbsoluteCoordinates(view.frame)
            addSubview(view)
            view.frame = view.convertFromAbsoluteCoordinates(frame)
        } else {
            addSubview(view)
        }
    }
}

Is there some solutions? thanks.. 😬

@jiachenmu
Copy link
Author

jiachenmu commented Nov 2, 2017

In LayoutKitDemo, i found this:

open class CircleImagePileView: UIView {

    open override func addSubview(_ view: UIView) {
        // Make sure views are inserted below existing views so that the first image in the face pile is on top.
        if let lastSubview = subviews.last {
            insertSubview(view, belowSubview: lastSubview)
        } else {
            super.addSubview(view)
        }
    }
}

override UIVisualEffectView.addSubview, is a solution?

@jiachenmu
Copy link
Author

What I guess above is a solution, here's an example:

class RootCardLayout: SizeLayout<VisualEffectView> {
    init(_ title: String, subtitle: String, info: String, size: CGSize, action: @escaping (() -> ())) {
        
        let titleLayout = LabelLayout.init(text: title, font: UIFont.cic.systemFont, numberOfLines: 1, viewReuseId: "title") { (label) in
            
        }
        
        let subtitleLayout = LabelLayout.init(text: subtitle, font: UIFont.boldSystemFont(ofSize: 20.0), numberOfLines: 0, viewReuseId: "subtitle") { (label) in
            
        }
        
    
        let infoHeight = info.cicHeight(size.width, font: UIFont.cic.preferred(.body))
        let infoLayout = SizeLayout<CICLabel>.init(height: infoHeight) { (label) in
            label.line(0)
                .text(info)
                .font(UIFont.preferredFont(forTextStyle: .body))
                .sizeTo(layout: .maxWidth(.screenWidth))
                .textColor(CIComponentKitThemeCurrentConfig.textColor)
                .longPressAction(.copy)
                .copyRange(NSMakeRange(0, 5))
            label.copySuccessClousure = {
                let tips = """
                            嫉妒使我高斯模糊

                            嫉妒使我氧化分解

                            嫉妒使我增减反同

                            嫉妒使我奇变偶不变符号看象限

                            嫉妒使我基因突变

                            嫉妒使我质壁分离

                            嫉妒使我泰拳警告

                            嫉妒使我弥散性血管内凝血
                           """
                CICHUD.showAlert("羡慕使我嫉妒", content: tips)
                CICHUD.showNotifier(title: "爱酱今天要元气满满哦~")
            }
        }
    
        let stackLayout = StackLayout<UIControl>.init(axis: .vertical,
                                                      spacing: 30,
                                                      sublayouts: [titleLayout, subtitleLayout, infoLayout]) { (control) in
                                                        control.addHandler(for: .touchUpInside, handler: { (_) in
                                                            action()
                                                        })
        }
        

        super.init(minWidth: size.width,
                   maxWidth: size.width,
                   maxHeight: size.height,
                   alignment: .center,
                   sublayout: InsetLayout.init(insets: UIEdgeInsetsMake(5, 5, 5, 5), sublayout: stackLayout)) { (view) in
            view.layer.cornerRadius = 6.0
            view.layer.masksToBounds = true
            view.layer.shadowColor = UIColor.white.cgColor
            view.effect = UIBlurEffect.init(style: .extraLight)
        }
    }
}

class VisualEffectView: UIVisualEffectView {
    override func addSubview(_ view: UIView) {
        print(view.classForCoder)
        if view is UIControl {
            self.contentView.addSubview(view)
        }else {
            super.addSubview(view)
        }
    }
}

override this method ,addSubview , but may not be the best solution (-_-#!)

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

No branches or pull requests

1 participant