<!--
{
  "availability" : [
    "iOS: 27.2.0 -",
    "iPadOS: 27.2.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "SwiftUI",
  "identifier" : "/documentation/SwiftUI/View/deviceMotionAnchor(manager:isEnabled:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "SwiftUI",
      "SwiftUI"
    ],
    "preciseIdentifier" : "s:7SwiftUI4ViewP012_CoreMotion_aB0E06deviceE6Anchor7manager9isEnabledQrSo15CMMotionManagerC_SbtF"
  },
  "title" : "deviceMotionAnchor(manager:isEnabled:)"
}
-->

# deviceMotionAnchor(manager:isEnabled:)

Specifies this view as the reference body for the motion manager’s
device-motion calculations.

```
nonisolated func deviceMotionAnchor(manager: CMMotionManager, isEnabled: Bool = true) -> some View
```

## Parameters

`manager`

The motion manager to specify this view as the body of.

`isEnabled`

Whether this view should be the manager’s body.

## Discussion

```
@State private var motionManager = CMMotionManager()

var body: some View {
    MyView()
        .deviceMotionAnchor(manager: motionManager)
}
```

If more than one view specifies itself as the body of the same manager,
the most recent one to do so becomes the body. Once a view stops being
the body, whether because it disappeared or because `isEnabled` became
`false`, the manager has no body until some view specifies one again.

Use `isEnabled` to pick between views which are all on screen. For
example, a map might anchor device motion to a puck, except while
navigating, when it anchors to a vehicle icon instead:

```
ZStack {
    Puck()
        .deviceMotionAnchor(manager: motionManager,
                            isEnabled: !isNavigating)
    VehicleIcon()
        .deviceMotionAnchor(manager: motionManager,
                            isEnabled: isNavigating)
}
```

---

Copyright &copy; 2026 Apple Inc. All rights reserved. | [Terms of Use](https://www.apple.com/legal/internet-services/terms/site.html) | [Privacy Policy](https://www.apple.com/privacy/privacy-policy)