SwiftEnrtyKit에서 customView도 쉽게 팝업 가능

6399 단어 Swift

사용할 라이브러리


swiftEntryKit
https://github.com/huri000/SwiftEntryKit

주의할 점


자체 제작 보기/보기 컨트롤러 팝업
width,height에constraint를 추가하지 않으면 표시되지 않습니다.
//ダメな具体例
let customView = UIView(frame: CGRect(x: 0, y: 0 , width: 300, height: 200))

//修正するとこうなる
let customView = UIView()
let widthConstraint = customView.widthAnchor.constraint(equalToConstant: 300)
widthConstraint.isActive = true
let heightConstraint = customView.heightAnchor.constraint(equalToConstant: 200)
heightConstraint.isActive = true

실제 함수

    private func showPopUp(){
        var attributes = EKAttributes.centerFloat
        attributes.position = .center
        attributes.displayDuration = .infinity
        attributes.entryBackground = .color(color: .white)
        attributes.entranceAnimation = .none
        attributes.exitAnimation = .translation
        attributes.screenInteraction = .dismiss

        let customView = UIView(frame: CGRect(x: 0, y: 0 , width: 300, height: 200))
        let widthConstraint = customView.widthAnchor.constraint(equalToConstant: 100)
        widthConstraint.isActive = true
        let heightConstraint = customView.heightAnchor.constraint(equalToConstant: 300)
        heightConstraint.isActive = true
        customView.backgroundColor = .orange
        SwiftEntryKit.display(entry: customView, using: attributes)
    }
부르고 싶은 곳self.showPopUP()으로 표시

참고 문헌

좋은 웹페이지 즐겨찾기