To change orientation programatically in swift 3, use the following way:
let value = UIInterfaceOrientation.landscapeRight.rawValue
UIDevice.current.setValue(value, forKey: "orientation")
You can use the orientations,
1. portrait
2. portraitUpsideDown
3. landscapeLeft
4. landscapeRight