Magnetic UI

Interfaces that feel a magnet. One small on-device model reads the iPhone's magnetometer and tells your views where the magnet is, whether it is really there, and when it taps the air. Input for any view or library.

Video coming soon

The model

One model reads the magnetometer every frame and answers three things. It is input only: pair it with any view or library.

Magnet.mfxl · v1.0 · 2 MB · MagnetKit · Model License

Where the magnet is

  • Reads One magnetometer change, plus the magnet's face and strength when you know them.
  • Answers Position in screen points, height above the glass, and its own uncertainty, over the screen or beside the phone.
  • Tested Real iPhone 15 Pro, median error: 1.2 cm over the screen, 2.0–2.7 cm with the magnet 1.5 cm beside the phone.

Whether it is really there

  • Reads The last 15 s of the field, and whether the phone was overloaded since its last zero.
  • Answers Presence (0–1) and the phone's own offset, so leftovers are cleared and a resting magnet is kept.
  • Tested Real iPhone 15 Pro: a magnet taken away after an overload recognised as gone 96–100 % of the time.

Air taps

  • Reads The last 1.28 s at 50 Hz. In a dip the field barely turns; in a sweep or a flick it does.
  • Answers A tap, about 0.1 s before the hand is back, with where it landed.
  • Tested Real iPhone 15 Pro: 11 of 11 taps over the top half, no false tap in 34 near misses.

Inside: three parts in one file, ~990k weights in half precision, run with Accelerate on every frame.

Built for the phone

Trained on physics and real magnets

The model learned from simulated magnets (sizes from a small ring to a large N52 block, every tilt and face, with sensor noise, drift and leftovers) and from real magnet sessions on an iPhone 15 Pro: a printed mat of known spots and recorded air taps. Those sessions tuned the simulator, retrained the air-tap part and tested every part. No user data.

On the phone, every frame

A 2 MB model in half precision, run with Accelerate. It ships inside your app: no server, no network request at runtime.

No permission prompt

The magnetometer is open to every app, so the magnet works the moment the screen appears.

Any magnet

A fridge magnet works; a small neodymium ring works best. iPhone with iOS 17 or newer, or Android 10 or newer.