Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- open class VKPopupView: NSObject
- {
- // MARK: Public properties
- /// Title of the `VKPopupView`. Appears above the contentView
- open var title: String?
- /// Content you want to display inside popup
- /// - Important: Max size of the contentView is `300x300`.
- /// - requires: `VKPopupView` will reset backgroundColor to `UIColor.clear`. It is done in order to match Apple's style
- open var contentView: UIView?
- {
- didSet
- {
- if let oldContent = oldValue
- {
- oldContent.removeFromSuperview()
- }
- if contentView != nil
- {
- self.adoptContentView()
- }
- }
- }
- /// Set background blur style
- /// - Note: Default is `UIBlurEffectStyle.light`
- open var backgroundBlurStyle: UIBlurEffectStyle = .light
- {
- didSet
- {
- self.viewOverlay.effect = UIBlurEffect(style: backgroundBlurStyle)
- }
- }
- /// Set popup blur style
- /// - Note: Default is `UIBlurEffectStyle.extraLight`
- open var contentViewBlurStyle: UIBlurEffectStyle = .extraLight
- {
- didSet
- {
- self.containerView.effect = UIBlurEffect(style: contentViewBlurStyle)
- }
- }
- /// Delegate of the VKPopupView
- open var delegate: VKPopupViewDelegate?
- /// Set the animation duration for show and hide
- /// - Note: Default is `0.4` seconds
- open var animationSpeed: TimeInterval = 0.4
- /// Constant of the content frame
- /// - Attention: Please use it as constant for all your content views
- open static let contentFrame = CGRect(x: 0, y: 0, width: 300, height: 300)
- // MARK: Private properties
- // Views
- /// Background overlay view
- fileprivate var viewOverlay = UIVisualEffectView()
- /// Container of the content view
- fileprivate var containerView = UIVisualEffectView()
- /// Title label
- /// - Note: It will not show up in `title` is `nil`
- fileprivate var labelTitle = UILabel()
- // Sizes
- /// Initial frame from where `VKPopupView` will fade in and fade out
- fileprivate var initialFrame: CGRect!
- /// Default frame which is used when `initialFrame` is `nil`
- fileprivate var zeroFrame = CGRect(x: UIScreen.main.bounds.midX, y: UIScreen.main.bounds.midY, width: 0, height: 0)
- /// Frame used when `VKPopupView` is shown
- fileprivate lazy var finalFrame: CGRect =
- {
- var size: CGFloat = 300
- let x: CGFloat = self.viewOverlay.bounds.midX - size / 2
- let y: CGFloat = self.viewOverlay.bounds.midY - size / 2
- return CGRect(x: x, y: y, width: size, height: size)
- }()
- // MARK: Init
- /// Init VKPopupView and set 'backgrundStyle' and 'contentViewStyle' properties
- ///
- /// - Parameters:
- /// - backgroundStyle: Set 'backgroundStyle' value
- /// - contentViewStyle: Set 'contentViewStyle' value
- ///
- /// Example:
- ///
- /// let popup = VKPopup(backgroundStyle: .dark, contentViewStyle: .light)
- /// ___
- public convenience init(backgroundStyle: UIBlurEffectStyle = .light, contentViewStyle: UIBlurEffectStyle = .extraLight)
- {
- self.init()
- self.backgroundBlurStyle = backgroundStyle
- self.contentViewBlurStyle = contentViewStyle
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement