Search code examples
objective-cioscocoa-touchautorotatescreen-rotation

Objective-C - Locking rotation in ABPeoplePickerNavigationController


My app uses only portrait mode. But ABPeoplePickerNavigationController supports landscape. Is it possible to have ABPeoplePickerNavigationController support only portrait mode?


Solution

  • Subclass it and override shouldAutorotateToInterfaceOrientation:

    // .h file
    @interface MMABPeoplePickerPortraitOnlyNavigationController : ABPeoplePickerNavigationController
    @end
    
    // .m file
    @implementation MMABPeoplePickerPortraitOnlyNavigationController
    
    - (BOOL)shouldAutorotateToInterfaceOrientation:(UIInterfaceOrientation)interfaceOrientation {
        return UIInterfaceOrientationIsPortrait(interfaceOrientation);
    }
    
    @end