-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
1. Taptic snippet working to enable haptic feedback.
2. Added Taptic functionality to Snippet scroll. 3. TapticGenerator has options for all types of haptic feedback.
- Loading branch information
1 parent
93a7d61
commit ca12bd1
Showing
11 changed files
with
183 additions
and
10 deletions.
There are no files selected for viewing
File renamed without changes.
Loading
Sorry, something went wrong. Reload?
Sorry, we cannot display this file.
Sorry, this file is invalid so it cannot be displayed.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file modified
BIN
+18.1 KB
(110%)
...eproj/project.xcworkspace/xcuserdata/elliottio.xcuserdatad/UserInterfaceState.xcuserstate
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
27 changes: 27 additions & 0 deletions
27
StoryboardSnippets/StoryboardSnippets/Snippets/Taptic/TapticGenerator.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,27 @@ | ||
// | ||
// TapticGenerator.swift | ||
// StoryboardSnippets | ||
// | ||
// Created by Elliott Io on 4/28/20. | ||
// Copyright © 2020 elliott io. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
class TapticGenerator { | ||
static func impact(_ style: UIImpactFeedbackGenerator.FeedbackStyle) { | ||
let generator = UIImpactFeedbackGenerator(style: style) | ||
generator.impactOccurred() | ||
} | ||
|
||
static func notification(_ type: UINotificationFeedbackGenerator.FeedbackType) { | ||
let generator = UINotificationFeedbackGenerator() | ||
generator.notificationOccurred(type) | ||
} | ||
|
||
static func selectionChanged() { | ||
let generator = UISelectionFeedbackGenerator() | ||
generator.selectionChanged() | ||
} | ||
} |
86 changes: 86 additions & 0 deletions
86
StoryboardSnippets/StoryboardSnippets/Snippets/Taptic/TapticViewController.swift
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,86 @@ | ||
// | ||
// TapticGenerator.swift | ||
// StoryboardSnippets | ||
// | ||
// Created by Elliott Io on 4/28/20. | ||
// Copyright © 2020 elliott io. All rights reserved. | ||
// | ||
|
||
import Foundation | ||
import UIKit | ||
|
||
//class TapticGenerator { | ||
// | ||
//} | ||
import UIKit | ||
|
||
class TapticViewController: UIViewController, UIPickerViewDataSource, UIPickerViewDelegate { | ||
var i = 0 | ||
@IBOutlet weak var picker: UIPickerView! | ||
var pickerData: [String] = [String]() | ||
|
||
override func viewDidLoad() { | ||
super.viewDidLoad() | ||
|
||
let btn = UIButton() | ||
btn.translatesAutoresizingMaskIntoConstraints = false | ||
view.addSubview(btn) | ||
|
||
btn.widthAnchor.constraint(equalToConstant: 128).isActive = true | ||
btn.heightAnchor.constraint(equalToConstant: 50).isActive = true | ||
btn.centerXAnchor.constraint(equalTo: view.centerXAnchor).isActive = true | ||
btn.centerYAnchor.constraint(equalTo: view.centerYAnchor).isActive = true | ||
|
||
btn.setTitle("Feel Taptic", for: .normal) | ||
btn.setTitleColor(.white, for: .normal) | ||
btn.backgroundColor = .secondarySystemBackground | ||
btn.layer.cornerRadius = Styles.buttonRadius | ||
btn.addTarget(self, action: #selector(tapped), for: .touchUpInside) | ||
|
||
// setup picker | ||
self.picker.delegate = self | ||
self.picker.dataSource = self | ||
pickerData = ["Heavy", "Medium", "Light", "Selection Changed", "Success", "Warning", "Error"] | ||
} | ||
|
||
override func didReceiveMemoryWarning() { | ||
super.didReceiveMemoryWarning() | ||
// Dispose of any resources that can be recreated. | ||
} | ||
|
||
// columns of picker | ||
func numberOfComponents(in pickerView: UIPickerView) -> Int { | ||
return 1 | ||
} | ||
|
||
// rows of picker | ||
func pickerView(_ pickerView: UIPickerView, numberOfRowsInComponent component: Int) -> Int { | ||
return pickerData.count | ||
} | ||
|
||
// component is the column | ||
func pickerView(_ pickerView: UIPickerView, titleForRow row: Int, forComponent component: Int) -> String? { | ||
return pickerData[row] | ||
} | ||
|
||
@objc func tapped() { | ||
switch (pickerData[picker.selectedRow(inComponent: 0)]) { | ||
case "Heavy": | ||
TapticGenerator.impact(.heavy) | ||
case "Medium": | ||
TapticGenerator.impact(.medium) | ||
case "Light": | ||
TapticGenerator.impact(.light) | ||
case "Success": | ||
TapticGenerator.notification(.success) | ||
case "Warning": | ||
TapticGenerator.notification(.warning) | ||
case "Error": | ||
TapticGenerator.notification(.error) | ||
case "Selection Changed": | ||
TapticGenerator.selectionChanged() | ||
default: | ||
TapticGenerator.selectionChanged() | ||
} | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters