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

change addMotionEffect optionally #260

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
24 changes: 24 additions & 0 deletions PKHUD/FrameView.swift
Original file line number Diff line number Diff line change
Expand Up @@ -64,4 +64,28 @@ internal class FrameView: UIVisualEffectView {
contentView.addSubview(_content)
}
}

func updateMottionEffects(isEnable: Bool) {
motionEffects = []

guard isEnable else {
return
}

let offset = 20.0

let motionEffectsX = UIInterpolatingMotionEffect(keyPath: "center.x", type: .tiltAlongHorizontalAxis)
motionEffectsX.maximumRelativeValue = offset
motionEffectsX.minimumRelativeValue = -offset

let motionEffectsY = UIInterpolatingMotionEffect(keyPath: "center.y", type: .tiltAlongVerticalAxis)
motionEffectsY.maximumRelativeValue = offset
motionEffectsY.minimumRelativeValue = -offset

let group = UIMotionEffectGroup()
group.motionEffects = [motionEffectsX, motionEffectsY]

addMotionEffect(group)
}

}
5 changes: 5 additions & 0 deletions PKHUD/HUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -35,6 +35,11 @@ public final class HUD {
set { PKHUD.sharedHUD.dimsBackground = newValue }
}

public static var enableMottionEffects: Bool {
get { return PKHUD.sharedHUD.enableMotionEffects }
set { PKHUD.sharedHUD.enableMotionEffects = newValue }
}

public static var allowsInteraction: Bool {
get { return PKHUD.sharedHUD.userInteractionOnUnderlyingViewsEnabled }
set { PKHUD.sharedHUD.userInteractionOnUnderlyingViewsEnabled = newValue }
Expand Down
10 changes: 10 additions & 0 deletions PKHUD/PKHUD.swift
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,16 @@ open class PKHUD: NSObject {
}
}

open var enableMotionEffects: Bool {
get {
return !container.frameView.motionEffects.isEmpty
}

set {
container.frameView.updateMottionEffects(isEnable: newValue)
}
}

open var isVisible: Bool {
return !container.isHidden
}
Expand Down