2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?

More than 3 years have passed since last update.

SwiftEnrtyKitでcustomViewも手軽にポップアップ表示

Posted at

##使用するライブラリ
swiftEntryKit
https://github.com/huri000/SwiftEntryKit

##注意するところ
自作のビュー/ビューコントローラーをpopupさせたい時、
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()で表示されます
ezgif.com-video-to-gif.gif

##参考文献
https://github.com/huri000/SwiftEntryKit/issues/165

2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2

Delete article

Deleted articles cannot be recovered.

Draft of this article would be also deleted.

Are you sure you want to delete this article?