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

Support iOS 9 target #108

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
34 changes: 28 additions & 6 deletions PanModal/Animator/PanModalPresentationAnimator.swift
Original file line number Diff line number Diff line change
Expand Up @@ -42,7 +42,21 @@ public class PanModalPresentationAnimator: NSObject {
/**
Haptic feedback generator (during presentation)
*/
private var feedbackGenerator: UISelectionFeedbackGenerator?
private var _feedbackGenerator: Any? = nil
@available(iOS 10.0, *)
fileprivate var feedbackGenerator: UISelectionFeedbackGenerator? {

set {
_feedbackGenerator = newValue
}

get {
if _feedbackGenerator == nil {
_feedbackGenerator = UISelectionFeedbackGenerator()
}
return _feedbackGenerator as? UISelectionFeedbackGenerator
}
}

// MARK: - Initializers

Expand All @@ -54,8 +68,11 @@ public class PanModalPresentationAnimator: NSObject {
Prepare haptic feedback, only during the presentation state
*/
if case .presentation = transitionStyle {
feedbackGenerator = UISelectionFeedbackGenerator()
feedbackGenerator?.prepare()

if #available(iOS 10.0, *) {
feedbackGenerator = UISelectionFeedbackGenerator()
feedbackGenerator?.prepare()
}
}
}

Expand Down Expand Up @@ -85,8 +102,10 @@ public class PanModalPresentationAnimator: NSObject {
panView.frame.origin.y = transitionContext.containerView.frame.height

// Haptic feedback
if presentable?.isHapticFeedbackEnabled == true {
feedbackGenerator?.selectionChanged()
if #available(iOS 10.0, *) {
if presentable?.isHapticFeedbackEnabled == true {
feedbackGenerator?.selectionChanged()
}
}

PanModalAnimator.animate({
Expand All @@ -95,7 +114,10 @@ public class PanModalPresentationAnimator: NSObject {
// Calls viewDidAppear and viewDidDisappear
fromVC.endAppearanceTransition()
transitionContext.completeTransition(didComplete)
self?.feedbackGenerator = nil

if #available(iOS 10.0, *) {
self?.feedbackGenerator = nil
}
}
}

Expand Down
4 changes: 2 additions & 2 deletions PanModalDemo.xcodeproj/project.pbxproj
Original file line number Diff line number Diff line change
Expand Up @@ -832,7 +832,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6UF7FN999R;
INFOPLIST_FILE = "$(SRCROOT)/Sample/Resources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand All @@ -853,7 +853,7 @@
CODE_SIGN_STYLE = Automatic;
DEVELOPMENT_TEAM = 6UF7FN999R;
INFOPLIST_FILE = "$(SRCROOT)/Sample/Resources/Info.plist";
IPHONEOS_DEPLOYMENT_TARGET = 10.0;
IPHONEOS_DEPLOYMENT_TARGET = 9.0;
LD_RUNPATH_SEARCH_PATHS = (
"$(inherited)",
"@executable_path/Frameworks",
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -26,13 +26,17 @@ class TransientAlertViewController: AlertViewController {

private func startTimer() {
timer?.invalidate()
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
self?.countdown -= 1
self?.updateMessage()
if #available(iOS 10.0, *) {
timer = Timer.scheduledTimer(withTimeInterval: 1.0, repeats: true) { [weak self] _ in
self?.updateMessage()
}
} else {
Timer.scheduledTimer(timeInterval: 1.0, target: self, selector: #selector(self.updateMessage), userInfo: nil, repeats: true)
}
}

@objc func updateMessage() {
countdown -= 1
guard countdown > 0 else {
invalidateTimer()
dismiss(animated: true, completion: nil)
Expand Down