Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/hyun99999/uifeedbackgeneratortutorial-ios
๐UIFeedbackGeneratorTutorial ํ
ํฑ ๋์์
https://github.com/hyun99999/uifeedbackgeneratortutorial-ios
Last synced: 27 days ago
JSON representation
๐UIFeedbackGeneratorTutorial ํ ํฑ ๋์์
- Host: GitHub
- URL: https://github.com/hyun99999/uifeedbackgeneratortutorial-ios
- Owner: hyun99999
- Created: 2022-02-17T01:42:36.000Z (about 3 years ago)
- Default Branch: main
- Last Pushed: 2022-02-17T01:48:33.000Z (about 3 years ago)
- Last Synced: 2024-11-25T21:35:53.186Z (3 months ago)
- Language: Swift
- Size: 28.3 KB
- Stars: 2
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
Awesome Lists containing this project
README
# UIFeedbackGeneratorTutorial-iOS
๐UIFeedbackGeneratorTutorial ํ ํฑ ๋์์ ### ๋ด์ฉ
- shake motion ์ ์ธ์ํด์ ํ๋ฉด์ ํ ์ ์ง๋ ์ถ๊ฐ
# ์์ ์
apple developer ๊ฐ๋ฐ์ ๋ฌธ์์์๋ ์์ดํฐ์์ ์ฌ์ฉํ ๋ ๋๋ ์ ์๋ "๋๋" ํน์ "๋" ํ๋ ์ด๋ฌํ ์ด๊ฐ ๊ฒฝํ์ haptic ์ผ๋ก ๋ช ์ํ๊ณ ์๋ค.
์ง๋๊ธฐ๋ฅ์ ์ถ๊ฐํ๊ธฐ ์ํด์ ํ ํฑ ๊ด๋ จํด์ ๊ณต๋ถ๋ฅผ ํ๋ค๊ฐ ํ ํฑ ํจํด์ ์ ํ๊ณ ๋ด๊ฐ ์ํ๋ ์ง๋์ ์๊ตฌ๋ ๋ผ๊ณ ๋๊ผ๋ค. ๊ทธ๋๋ ๊ณต๋ถํ๊ฒ ์์ฌ์์ ๋จ๊ธด๋ค.
### Haptics ์ Vibrate
- ๋น๋ฐ๋ฒํธ ์ ๋ ฅ ์(ex.์นด์นด์คํ์ด) โ ํ ํฑ
- ์ค์ํ ํ์ ๋ฑ์ฅ ์(ex.์นด์นด์คํก ํ์์ฝ๋) โ ๋ฐ์ด๋ธ๋ ์ดํธ## ๐ [HIG - Haptics](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/)
- Human Interface Guidelines ์ ํ์ํ ๋ด์ฉ์ ์ ๋ฆฌํด๋ณด์. ๋ฌธ์์์ ์ฌ๋ฌ ํจํด์ ์ง๋ ๋ฏธ๋์ด๊น์ง ์ ๊ณตํ๋ ๋ ์์ธํ ๋ด์ฉ์ ๋งํฌ๋ฅผ ํ์ธํด๋ณด์.
### Haptics
ํ ํฑ์ ์ฌ๋๋ค์ ์ด๊ฐ์ ๊ด์ฌํ์ฌ ํ๋ฉด ์ธํฐํ์ด์ค์ ์ํธ์์ฉํ๋ ๊ฒฝํ์ ํฅ์์ํจ๋ค. ์๋ฅผ ๋ค์ด ์์คํ ์ ์๊ฐ ๋ฐ ์ฒญ๊ฐ ํผ๋๋ฐฑ๊ณผ ๋๋ถ์ด ํ ํฑ์ ์ฌ์ํ์ฌ Apple Pay ๊ฑฐ๋์ ํ์ธ์ ๊ฐ์กฐ ํ์ํฉ๋๋ค. ๋ํ picker ๋ฅผ ์คํฌ๋กคํ๊ฑฐ๋ switch ๋ฅผ ํ ๊ธํ๋ ๊ฒ๊ณผ ๊ฐ์ ํฐ์น ์ ์ค์ฒ ๋ฐ ์ํธ์์ฉ์ ๊ฐ์กฐํ ์ ์๋ค. ๊ฐ๋ฐ์ ์ง์นจ์ [Animation and Haptics](https://developer.apple.com/documentation/uikit/animation_and_haptics) ๋ฅผ ์ฐธ์กฐํด๋ผ.
์ง์๋๋ iPhone ๋ชจ๋ธ์์๋ ์ฌ๋ฌ๊ฐ์ง ๋ฐฉ๋ฒ์ผ๋ก ์ฑ์ ํ ํฑ์ ์ถ๊ฐํ ์ ์๋ค.
- Use standard UI elements โ likeย [switches](https://developer.apple.com/documentation/uikit/uiswitch),ย [sliders](https://developer.apple.com/documentation/uikit/uislider), andย [pickers](https://developer.apple.com/documentation/uikit/uipickerview)ย โ that play Apple-designed system haptics by default.
- When it makes sense, use a feedback generator to play one of several predefined haptic patterns in the categories ofย [notification](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/#notification),ย [impact](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/#impact), andย [selection](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/#selection)ย (for developer guidance, seeย [UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)).
- In situations where you want more control, compose and play your own haptic patterns. For guidance, seeย [Creating Custom Haptic Patterns](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/#creating-custom-haptic-patterns).์์คํ ์ ๊ณต ์ปจํธ๋กค ๋ฐ ํ ํฑ์ ์ฌ์ฉํ๋ ๊ฒฝ์ฐ iOS ๋ ๊ฐ๋์ ํผ๋๋ฐฑ์ ๋์์ ๊ด๋ฆฌํ๋ค. ์๋ฅผ ๋ค์ด ์ค์์น๋ ๋ฏธ๋ฌํ tap ์ ์๋์ผ๋ก ์ฌ์ํ๊ณ "success" notification ์ ๋ํ feedback generator ๋ ์๋์ ํจํด์ ์ฌ์ํ๋ค. ์ฌ๋๋ค์ ์์คํ ์ ์ ํ ํ์ ์ธ์ํ๋ฏ๋ก ๋ฌธ์ํ๋ ์๋ฏธ์ ๋ฐ๋ผ ์ฌ์ฉํ๋ ๊ฒ์ด ์ค์ํ๋ค.
(์์ HIG ๋ฌธ์์์๋ ์ค์ ๋ก ํ ํฑ์ ์ฒดํํด๋ณผ ์ ์๋ค! ๊ผญ ๋ค์ด๊ฐ์ ํ์ธํด๋ณด๊ธธ ๋ฐ๋๋ค.)
### Notification
Notification haptics ๋ ์์ ๋๋ ์์ ์ ๊ฒฐ๊ณผ์ ๋ํ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ค.
- ๋งํฌ์์ ์ฌ๋ฌ ํจํด์ ํ์ธํ ์ ์๋ค.
### Impact
Impact haptics ๋ ์๊ฐ์ ๊ฒฝํ์ ๋ณด์ํ๋๋ฐ ์ฌ์ฉํ ์ ์๋ ๋ฌผ๋ฆฌ์ ๋ฉํํฌ๋ฅผ ์ ๊ณตํ๋ค. ์๋ฅผ ๋ค์ด ์ฌ๋๋ค์ view ๊ฐ ์ ์๋ฆฌ์ ๊ณ ์ ๋ ๋ ํญ์ ๋๋ผ๊ฑฐ๋ ๋ ๊ฐ์ ๋ฌด๊ฑฐ์ด ๋ฌผ์ฒด๊ฐ ์ถฉ๋ํ ๋ ์ฟต ์๋ฆฌ๋ฅผ ๋๋ ์ ์์ต๋๋ค.
- ๋งํฌ์์ ์ฌ๋ฌ ํจํด์ ํ์ธํ ์ ์๋ค.
### Selection
Selection haptics ๋ UI ์์์ ๊ฐ์ด ๋ณ๊ฒฝ๋๋ ๋์ ํผ๋๋ฐฑ์ ์ ๊ณตํ๋ค.
- ๋งํฌ์์ ์ฌ๋ฌ ํจํด์ ํ์ธํ ์ ์๋ค.
์์คํ ์์ ์ ๊ณตํ๋ ํ ํฑ์ ์ฌ์ฉํ๋ ์์ฒด์ ์ผ๋ก ๋ง๋ค๋ ์ฌ๋๋ค์ ๋ชฉํ์์ ๋ฐฉํดํ์ง ์์ผ๋ฉด์ ์ฌ์ฉ์ ๊ฒฝํ์ ํ๋ถํ๊ฒ ๋ง๋๋ ๋ฐฉ์์ผ๋ก ํ ํฑ์ ์ฌ์ฉํ๋ ๊ฒ์ด ์ค์ํ๋ค.
---
์ดํ์ HIG ๋ฌธ์๋ **haptics ๋ก ์ธํฐํ์ด์ค๋ฅผ ๋์์ธํ๋ ๋ด์ฉ**๊ณผ **Custom Haptic Patterns ๋ฅผ ๋ง๋๋ ๋ด์ฉ**์ ์ ๊ณตํ๋ค.
์ด์ ๊ฐ๋ฐ์ ๋ฌธ์๋ฅผ ์ดํด๋ณด์!
## ๐ [Apple Developer - Animation and Haptics](https://developer.apple.com/documentation/uikit/animation_and_haptics)
### ๐ Haptick Feedback
Provide haptic feedback in response to specific types of events.
- [classย UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)
: The abstract superclass for all feedback generators.
- [classย UIImpactFeedbackGenerator](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator)
: A concreteย [UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)ย subclass that creates haptics to simulate physical impacts.
- [classย UINotificationFeedbackGenerator](https://developer.apple.com/documentation/uikit/uinotificationfeedbackgenerator)
: A concreteย [UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)ย subclass that creates haptics to communicate successes, failures, and warnings.
- [classย UISelectionFeedbackGenerator](https://developer.apple.com/documentation/uikit/uiselectionfeedbackgenerator)
: A concreteย [UIFeedbackGenerator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator)ย subclass that creates haptics to indicate a change in selection.
## ๐ ์๋ฆฌ
To use a feedback generator, the following are required:
1. [Instantiating the Generator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator#2555404)
- feedback ์ ์์ฑํ๋ ค๋ฉด ๋จผ์ `UIFeedbackGenerator` ํด๋์ค์ ๊ตฌ์ฒด์ ์ธ ํ์ํด๋์ค(`UIImpactFeedbackGenerator`, `UISelectionFeedbackGenerator`, or `UINotificationFeedbackGenerator`) ์ค ํ๋๋ฅผ ์ธ์คํด์คํ ํด์ผํฉ๋๋ค.
2. [Preparing the Generator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator#2555405)ย (optional)
- generator ๋ฅผ preparing ํ๋ฉด์ feedback ์ ํธ๋ฆฌ๊ฑฐํ ๋ ๋๊ธฐ์๊ฐ์ ์ค์ผ ์ ์๋ค. ์ด๊ฒ์ ์๋ฆฌ ๋๋ ์๊ฐ์ ์ ํธ์ ๋งค์นํ ๋ ํนํ ์ค์ํ๋ค.
- generator ์ [prepare()](https://developer.apple.com/documentation/uikit/uifeedbackgenerator/2369818-prepare) ๋ฉ์๋๋ฅผ ํธ์ถํ๋ฉด Taptic Engine ์ด ์ค๋น์ํ๊ฐ ๋๋ค. ํ์๋ฅผ ๋ณด์กดํ๊ธฐ ์ํด์ Taptic Engine ์ ์ด ๋จ์์ ์งง์ ์๊ฐ๋์ ์ด ์ํ๋ฅผ ์ ์งํ๊ฑฐ๋ ํผ๋๋ฐฑ์ ํธ๋ฆฌ๊ฑฐํ ๋๊น์ง ์ ์งํฉ๋๋ค.
- ๋ง์ฝ, prepare() ๋ฉ์๋๋ฅผ ํธ์ถํ ๋ค์ ์ฆ์ ํผ๋๋ฐฑ์ ํธ๋ฆฌ๊ฑฐํ๋ฉด ์์คํ ์ Taptic Engine ์ ์ค๋น๋ ์ํ๋ก ์ ํํ ์๊ฐ์ด ์ถฉ๋ถํ์ง ์๊ณ , ์ง์ฐ์๊ฐ์ด ์ค์ด๋ค์ง ์์ ์ ์๋ค. ๋ฐ๋ฉด์, prepare() ๋ฉ์๋๋ฅผ ๋๋ฌด ์ผ์ฐ ํธ์ถํ๋ฉด ํผ๋๋ฐฑ์ ํธ๋ฆฌ๊ฑฐํ๊ธฐ ์ ์ Taptic Engine ์ ๋ค์ ์ฌ์ฉ๋์ง ์๋ ์ํ๊ฐ ๋๋ค.(์๋์ ์ฝ๋๋ฅผ ๋ณด๊ฒ๋๋ฉด ๋ฒํผ์ด ํด๋ฆญ๋๊ธฐ ์ ์ generator ๋ฅผ ์ค๋นํ๊ณ , ์ก์ ์ด ์คํ๋ ๋ ํธ๋ฆฌ๊ฑฐํ๋ ๋ชจ์ต์ ๋ณผ ์ ์๋ค.)
3. [Triggering Feedback](https://developer.apple.com/documentation/uikit/uifeedbackgenerator#2555415)
- ๊ฐ feedback generator ํ์ ํด๋์ค๋ ๊ณ ์ ํ ํธ๋ฆฌ๊ฑฐ ๋ฐฉ๋ฒ์ ๊ฐ์ง๋ค. ํธ๋ฆฌ๊ฑฐ ํ๊ธฐ ์ํด์ [impactOccurred()](https://developer.apple.com/documentation/uikit/uiimpactfeedbackgenerator/2374287-impactoccurred),ย [selectionChanged()](https://developer.apple.com/documentation/uikit/uiselectionfeedbackgenerator/2374284-selectionchanged), orย [notificationOccurred(_:)](https://developer.apple.com/documentation/uikit/uinotificationfeedbackgenerator/2369826-notificationoccurred) ์ ์ ์ ํ๊ฒ ํธ์ถํด์ผํ๋ค.
- ์ด๋ฐ ๋ฉ์๋๋ค์ ํธ์ถํด๋ haptic ์ด ์ง์ ์ฌ์๋์ง๋ ์๋๋ค. ๋์ ์์คํ ์ ์ด๋ฒคํธ๋ฅผ ์๋ฆฐ๋ค. ๊ทธ๋ฐ ๋ค์ ์์คํ ์ applicationโs state, amount of bateery power remaining , factors ๋ค์ ๊ธฐ๋ฐ์ผ๋ก haptic ์ ์ฌ์ํ ์ง ์ฌ๋ถ๋ฅผ ๊ฒฐ์ ํฉ๋๋ค.---
**For example, haptic feedback is currently played only:**
- On a device with a supported Taptic Engine(iPhone 6s ์ดํ์ ๋ชจ๋ iPhone ๋ฐ Apple watch, MacBook, Trackpad ๋ฑ์ ํ์ฌ๋์ด์์)
- When the app is running in the foreground
- When the System Haptics setting is enabled---
- ํผ๋๋ฐฑ์ ์ฌ์ํ ์ง ์ฌ๋ถ์ ๋ํด์ ์์คํ ์ ์ ๋ขฐํด๋ผ. ์กฐ๊ฑด๋ถ๋ก ํผ๋๋ฐฑ์ ํธ๋ฆฌ๊ฑฐํ๋ ค ํ์ง ๋ง์๋ผ.
4. [Releasing the Generator](https://developer.apple.com/documentation/uikit/uifeedbackgenerator#2555460)ย (optional).
- ๋ ์ด์ ์ค๋น๋ generator ํ์์์ผ๋ฉด generatro object ์ ์ฐธ์กฐ๋ฅผ ์ ๊ฑฐํ๊ณ , ์์คํ ์์ deallocate ํ๋๋ก ํ๋ค. ์ด๋ ๊ฒ ํ๋ฉด Taptic Engine ์ ๋ค์ ์ฌ์ฉํ์ง ์๋ ์ํ๋ก ๋ง๋ค ์ ์๋ค.(์๋์ ์ฝ๋๋ฅผ ๋ณด๊ฒ๋๋ฉด ํ ํฑ ๋์ ์ดํ ๋ง์ง๋ง์ generator ์ nil ์ ํ ๋นํ์ฌ ํด์ ํ๋ ๊ฒ์ ๋ณผ ์ ์๋ค.)
- generator ์ ์๋ฌด๋ฐ ์ฐธ์กฐ๊ฐ ์์ผ๋ฉด ์์คํ ์ deallocate ํ๋ค.
## ๐์์ํ๊ธฐ
- ๋ชจ๋ ํ ํฑ์ ์ฒดํํด๋ณด๊ธฐ ์ํจ์ด๊ธฐ ๋๋ฌธ์ ๊ฒฝ์ฐ์ ๋ฐ๋ผ generator ๋ฅผ prepare ํ๊ฑฐ๋ release ํ๋ ์ฝ๋๋ ์์ ์ ์๋ค.
### UINotificationFeedbackGenerator
```swift
import UIKitclass ViewController: UIViewController {
// MARK: - Properties
var notificationFeedbackGenerator: UINotificationFeedbackGenerator?
// ...
// MARK: - View Life Cycle
override func viewDidLoad() {
super.viewDidLoad()
setNotificationFeedbackGenerator()
}
// UINotificationFeedbackGenerator action
@IBAction func touchNotificationSuccessButton(_ sender: Any) {
notificationFeedbackGenerator?.notificationOccurred(.success)
}
@IBAction func touchNotificationWarningButton(_ sender: Any) {
notificationFeedbackGenerator?.notificationOccurred(.warning)
}
@IBAction func touchNotificationErrorButton(_ sender: Any) {
notificationFeedbackGenerator?.notificationOccurred(.error)
}
}// MARK: - Extensions
extension ViewController {
/// set UINotificationFeedbackGenerator
private func setNotificationFeedbackGenerator() {
notificationFeedbackGenerator = UINotificationFeedbackGenerator()
notificationFeedbackGenerator?.prepare()
}
}
```### UIImpactFeedbackGenerator
```swift
import UIKitclass ViewController: UIViewController {
// MARK: - Properties
// ...
var impactFeedbackGenerator: UIImpactFeedbackGenerator?
// MARK: - View Life Cycle
override func viewDidLoad() {
// ...
}
// UIImpactFeedbackGenerator action
@IBAction func touchImpactHeavyButton(_ sender: Any) {
impactFeedbackGenerator = UIImpactFeedbackGenerator(style: .heavy)
impactFeedbackGenerator?.impactOccurred()impactFeedbackGenerator = nil
}
@IBAction func touchImpactMediumButton(_ sender: Any) {
impactFeedbackGenerator = UIImpactFeedbackGenerator(style: .medium)
impactFeedbackGenerator?.impactOccurred()impactFeedbackGenerator = nil
}
@IBAction func touchImpactLightButton(_ sender: Any) {
impactFeedbackGenerator = UIImpactFeedbackGenerator(style: .light)
impactFeedbackGenerator?.impactOccurred()impactFeedbackGenerator = nil
}
}
```### UISelectionFeedbackGenerator
```swift
import UIKitclass ViewController: UIViewController {
// MARK: - Properties
// ...
var selectionFeedbackGenerator: UISelectionFeedbackGenerator?
// MARK: - View Life Cycle
override func viewDidLoad() {
// ..
}
// UISelectionFeedbackGenerator action
@IBAction func touchSelectionButton(_ sender: Any) {
selectionFeedbackGenerator = UISelectionFeedbackGenerator()
selectionFeedbackGenerator?.selectionChanged()selectionFeedbackGenerator = nil
}
}```
### ๋ทฐ
- ๋ฒํผ์ ์์ฑํด์ Haptic ์ ์ฒดํํ ์ ์๋๋ก ๊ตฌ์ฑ
---
### ๊นํ๋ธ :
[GitHub - hyun99999/UIFeedbackGeneratorTutorial-iOS: ๐UIFeedbackGeneratorTutorial ํ ํฑ ๋์์ ](https://github.com/hyun99999/UIFeedbackGeneratorTutorial-iOS)
[GitHub - 28th-SOPT-iOS-CloneCoding/MiraClone-KimHyunGyu: ๐ง ์์ ๋ฏธ๋ผํด๋ก ์ฝ๋ฉ ๊นํ๊ท](https://github.com/28th-SOPT-iOS-CloneCoding/MiraClone-KimHyunGyu)
---
### ์ฐธ๊ณ :
[iOS ) Haptic Feedback](https://zeddios.tistory.com/726)
[Haptics - User Interaction - iOS - Human Interface Guidelines - Apple Developer](https://developer.apple.com/design/human-interface-guidelines/ios/user-interaction/haptics/)