<!--
{
  "availability" : [
    "iOS: 26.0.0 -",
    "iPadOS: 26.0.0 -"
  ],
  "documentType" : "symbol",
  "framework" : "AVFoundation",
  "identifier" : "/documentation/AVFoundation/AVCaptureDevice/setDynamicAspectRatio(_:completionHandler:)",
  "metadataVersion" : "0.1.0",
  "role" : "Instance Method",
  "symbol" : {
    "kind" : "Instance Method",
    "modules" : [
      "AVFoundation"
    ],
    "preciseIdentifier" : "c:objc(cs)AVCaptureDevice(im)setDynamicAspectRatio:completionHandler:"
  },
  "title" : "setDynamicAspectRatio(_:completionHandler:)"
}
-->

# setDynamicAspectRatio(_:completionHandler:)

Updates the dynamic aspect ratio of the device.

```
func setDynamicAspectRatio(_ dynamicAspectRatio: AVCaptureDevice.AspectRatio, completionHandler handler: (@Sendable (CMTime, (any Error)?) -> Void)? = nil)
```

## Parameters

`dynamicAspectRatio`

The new [`AVCaptureDevice.AspectRatio`](/documentation/AVFoundation/AVCaptureDevice/AspectRatio) the device should output.

`handler`

A block called by the device when `dynamicAspectRatio` is set to the value specified. If you call [`setDynamicAspectRatio(_:completionHandler:)`](/documentation/AVFoundation/AVCaptureDevice/setDynamicAspectRatio(_:completionHandler:)) multiple times, the completion handlers are called in FIFO order. The block receives a timestamp which matches that of the first buffer to which all settings have been applied. Note that the timestamp is synchronized to the device clock, and thus must be converted to the [`synchronizationClock`](/documentation/AVFoundation/AVCaptureSession/synchronizationClock) prior to comparison with the timestamps of buffers delivered via an [`AVCaptureVideoDataOutput`](/documentation/AVFoundation/AVCaptureVideoDataOutput). You may pass `nil` for the `handler` parameter if you do not need to know when the operation completes.

## Discussion

This is the only way of setting [`dynamicAspectRatio`](/documentation/AVFoundation/AVCaptureDevice/dynamicAspectRatio). This method throws an `NSInvalidArgumentException` if `dynamicAspectRatio` is not a supported aspect ratio found in the device’s activeFormat’s [`supportedDynamicAspectRatios`](/documentation/AVFoundation/AVCaptureDevice/Format/supportedDynamicAspectRatios). This method throws an `NSGenericException` if you call it without first obtaining exclusive access to the device using [`lockForConfiguration()`](/documentation/AVFoundation/AVCaptureDevice/lockForConfiguration()).

---

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)