First of all the viewController to which orientations need to supported must implement the below method passing the supported orientations.
- (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)toInterfaceOrientation
Later to manually rotate the view set the device orientation directly using
[[UIDevice currentDevice] setOrientation:UIInterfaceOrientationPortrait];
if this doesn't work use
[[UIApplication sharedApplication] setStatusBarOrientation:UIInterfaceOrientationPortrait animated:YES];
remember if you return NO for the setting orientation in shouldAutoRotate
this may not work. Also check this in both ios5 & ios6, i have tried in ios5.
EDIT: For iOS5 or iOS6 where setOrientation
doesn't exist
[[UIDevice currentDevice] performSelector:NSSelectorFromString(@"setOrientation:") withObject:(id)UIInterfaceOrientationPortrait];
this works fine, but this may be a private api now.