728x90
안녕하세. iOSangBong입니다.
오늘은 Swift에서 쉐이크모션을 사용하는 방법에 대해 알아보겠습니다.
현재 카카오톡에서 흔들기 모션을 하면
여러 가지 기능을 설정해놓을 수 있는 화면으로 이동하고 있습니다.
이와같은 기능을 한번 알아보죠!
shake 모션을 사용하려는 ViewController로 이동해서
viewDidLoad처럼 motion을 쳐보면
이와 같이 motionBegan, motionEnded, motionCancelled가 나옵니다.
딱 보면 어떤식으로 사용하는지 느낌이 오시죠?
motionBegan: 모션 이벤트가 시작되었음을 알려줌
motionEnded: 모션 이벤트가 종료되었음을 알려줌
motionCancelled: 모션 이벤트가 취소되었음을 알려줌
여기서 간단하게 motion의 종류를 나타내는 EventSubType을 보자면
정말 많은걸 볼 수 있다...
remote관련 된건 외부악세사리로 제어하기 위한 것이기 때문에 Pass
우리는 motionShake에 집중해보자.
이런식으로 코드를 작성한다음
디바이스에 빌드해서 확인하면
로그가 잘찍히는걸 알 수 있다.
원하는 액션을 넣어주면 Shake 기능에 원하는 기능을 추가할 수 있습니다~!
프로젝트에 잘 참고해보세요.
다들 즐코딩하세요. 그럼 이만~
728x90
'Swift' 카테고리의 다른 글
[iOS][Swift] LocalAuthentication Face ID & Touch ID 생체인식 간단하게 알아보기 (0) | 2024.08.03 |
---|---|
[iOS][Swift] 'keyWindow' was deprecated 간단하게 해결하기 (0) | 2023.08.11 |
[iOS][Swift] NWPathMonitor 네트워크 간단하게 감지하기 (0) | 2023.07.26 |
[iOS][Swift] MQTT 간단하게 연결하기 (0) | 2023.07.22 |
[iOS][Swift] QR Code 간단하게 만들기 (0) | 2023.07.12 |