1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 |
import SwiftUI import CoreMotion struct ContentView: View { @State private var message = "Mueve tu mano" let motionManager = CMMotionManager() var body: some View { VStack { Text(message) .font(.title) Spacer() } .onAppear { startMotionUpdates() } } func startMotionUpdates() { if motionManager.isAccelerometerAvailable { motionManager.accelerometerUpdateInterval = 0.1 motionManager.startAccelerometerUpdates(to: .main) { data, error in guard let acceleration = data?.acceleration else { return } detectHandMovement(acceleration) } } } func detectHandMovement(_ acceleration: CMAcceleration) { let threshold = 1.0 // Ajusta el umbral según sea necesario if acceleration.x > threshold { message = "Movimiento a la derecha" } else if acceleration.x < -threshold { message = "Movimiento a la izquierda" } else if acceleration.y > threshold { message = "Mano hacia arriba" } else if acceleration.y < -threshold { message = "Mano hacia abajo" } } } @main struct WatchApp: App { var body: some Scene { WindowGroup { ContentView() } } } |