UIFeedbackGeneratorTutorial-iOS
λ΄μ©
- shake motion μ μΈμν΄μ νλ©΄μ ν μ μ§λ μΆκ°
μμ μ
apple developer κ°λ°μ λ¬Έμμμλ μμ΄ν°μμ μ¬μ©ν λ λλ μ μλ "λλ" νΉμ "λ" νλ μ΄λ¬ν μ΄κ° κ²½νμ haptic μΌλ‘ λͺ μνκ³ μλ€.
μ§λκΈ°λ₯μ μΆκ°νκΈ° μν΄μ ν ν± κ΄λ ¨ν΄μ 곡λΆλ₯Ό νλ€κ° ν ν± ν¨ν΄μ μ νκ³ λ΄κ° μνλ μ§λμ μꡬλ λΌκ³ λκΌλ€. κ·Έλλ 곡λΆνκ² μμ¬μμ λ¨κΈ΄λ€.
Haptics μ Vibrate
- λΉλ°λ²νΈ μ λ ₯ μ(ex.μΉ΄μΉ΄μ€νμ΄) β ν ν±
- μ€μν νμ λ±μ₯ μ(ex.μΉ΄μΉ΄μ€ν‘ νμμ½λ) β λ°μ΄λΈλ μ΄νΈ
π
HIG - Haptics
- Human Interface Guidelines μ νμν λ΄μ©μ μ 리ν΄λ³΄μ. λ¬Έμμμ μ¬λ¬ ν¨ν΄μ μ§λ λ―Έλμ΄κΉμ§ μ 곡νλ λ μμΈν λ΄μ©μ λ§ν¬λ₯Ό νμΈν΄λ³΄μ.
Haptics
ν ν±μ μ¬λλ€μ μ΄κ°μ κ΄μ¬νμ¬ νλ©΄ μΈν°νμ΄μ€μ μνΈμμ©νλ κ²½νμ ν₯μμν¨λ€. μλ₯Ό λ€μ΄ μμ€ν μ μκ° λ° μ²κ° νΌλλ°±κ³Ό λλΆμ΄ ν ν±μ μ¬μνμ¬ Apple Pay κ±°λμ νμΈμ κ°μ‘° νμν©λλ€. λν picker λ₯Ό μ€ν¬λ‘€νκ±°λ switch λ₯Ό ν κΈνλ κ²κ³Ό κ°μ ν°μΉ μ μ€μ² λ° μνΈμμ©μ κ°μ‘°ν μ μλ€. κ°λ°μ μ§μΉ¨μ Animation and Haptics λ₯Ό μ°Έμ‘°ν΄λΌ.
μ§μλλ iPhone λͺ¨λΈμμλ μ¬λ¬κ°μ§ λ°©λ²μΌλ‘ μ±μ ν ν±μ μΆκ°ν μ μλ€.
- Use standard UI elements β like switches, sliders, and pickers β 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, impact, and selection (for developer guidance, see UIFeedbackGenerator).
- In situations where you want more control, compose and play your own haptic patterns. For guidance, see 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
π
Haptick Feedback
Provide haptic feedback in response to specific types of events.
: The abstract superclass for all feedback generators.
: A concrete UIFeedbackGenerator subclass that creates haptics to simulate physical impacts.
: A concrete UIFeedbackGenerator subclass that creates haptics to communicate successes, failures, and warnings.
: A concrete UIFeedbackGenerator subclass that creates haptics to indicate a change in selection.
π
μ리
To use a feedback generator, the following are required:
- feedback μ μμ±νλ €λ©΄ λ¨Όμ
UIFeedbackGenerator
ν΄λμ€μ ꡬ체μ μΈ νμν΄λμ€(UIImpactFeedbackGenerator
,UISelectionFeedbackGenerator
, orUINotificationFeedbackGenerator
) μ€ νλλ₯Ό μΈμ€ν΄μ€ν ν΄μΌν©λλ€.
- Preparing the Generator (optional)
- generator λ₯Ό preparing νλ©΄μ feedback μ νΈλ¦¬κ±°ν λ λκΈ°μκ°μ μ€μΌ μ μλ€. μ΄κ²μ μ리 λλ μκ°μ μ νΈμ 맀μΉν λ νΉν μ€μνλ€.
- generator μ prepare() λ©μλλ₯Ό νΈμΆνλ©΄ Taptic Engine μ΄ μ€λΉμνκ° λλ€. νμλ₯Ό 보쑴νκΈ° μν΄μ Taptic Engine μ μ΄ λ¨μμ 짧μ μκ°λμ μ΄ μνλ₯Ό μ μ§νκ±°λ νΌλλ°±μ νΈλ¦¬κ±°ν λκΉμ§ μ μ§ν©λλ€.
- λ§μ½, prepare() λ©μλλ₯Ό νΈμΆν λ€μ μ¦μ νΌλλ°±μ νΈλ¦¬κ±°νλ©΄ μμ€ν μ Taptic Engine μ μ€λΉλ μνλ‘ μ νν μκ°μ΄ μΆ©λΆνμ§ μκ³ , μ§μ°μκ°μ΄ μ€μ΄λ€μ§ μμ μ μλ€. λ°λ©΄μ, prepare() λ©μλλ₯Ό λ무 μΌμ° νΈμΆνλ©΄ νΌλλ°±μ νΈλ¦¬κ±°νκΈ° μ μ Taptic Engine μ λ€μ μ¬μ©λμ§ μλ μνκ° λλ€.
(μλμ μ½λλ₯Ό 보κ²λλ©΄ λ²νΌμ΄ ν΄λ¦λκΈ° μ μ generator λ₯Ό μ€λΉνκ³ , μ‘μ μ΄ μ€νλ λ νΈλ¦¬κ±°νλ λͺ¨μ΅μ λ³Ό μ μλ€.)
- κ° feedback generator νμ ν΄λμ€λ κ³ μ ν νΈλ¦¬κ±° λ°©λ²μ κ°μ§λ€. νΈλ¦¬κ±° νκΈ° μν΄μ impactOccurred(), selectionChanged(), or 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
- νΌλλ°±μ μ¬μν μ§ μ¬λΆμ λν΄μ μμ€ν μ μ λ’°ν΄λΌ. 쑰건λΆλ‘ νΌλλ°±μ νΈλ¦¬κ±°νλ € νμ§ λ§μλΌ.
- Releasing the Generator (optional).
- λ μ΄μ μ€λΉλ generator νμμμΌλ©΄ generatro object μ μ°Έμ‘°λ₯Ό μ κ±°νκ³ , μμ€ν μμ deallocate νλλ‘ νλ€. μ΄λ κ² νλ©΄ Taptic Engine μ λ€μ μ¬μ©νμ§ μλ μνλ‘ λ§λ€ μ μλ€.
(μλμ μ½λλ₯Ό 보κ²λλ©΄ ν ν± λμ μ΄ν λ§μ§λ§μ generator μ nil μ ν λΉνμ¬ ν΄μ νλ κ²μ λ³Ό μ μλ€.)
- generator μ μλ¬΄λ° μ°Έμ‘°κ° μμΌλ©΄ μμ€ν μ deallocate νλ€.
π
μμνκΈ°
- λͺ¨λ ν ν±μ 체νν΄λ³΄κΈ° μν¨μ΄κΈ° λλ¬Έμ κ²½μ°μ λ°λΌ generator λ₯Ό prepare νκ±°λ release νλ μ½λλ μμ μ μλ€.
UINotificationFeedbackGenerator
import UIKit
class 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
import UIKit
class 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
import UIKit
class 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 - 28th-SOPT-iOS-CloneCoding/MiraClone-KimHyunGyu:
μ°Έκ³ :
Haptics - User Interaction - iOS - Human Interface Guidelines - Apple Developer