Lock application orientation in Symbian
Contents |
Overview
This example shows how to lock the application orientation to landscape.
Preconditions
- Symbian SDK is installed
Source
Option 1:
Lock the orientation when the UI is constructed in a CAknViewAppUi-derived class:
#include <aknViewAppUi.h>
#include <e32std.h>
class CMyAppUi : public CAknViewAppUi
{
// ...
};
void CMyAppui::ConstructL()
{
// Locks the orientation to landscape, similarly,
// use EAppOrientationPortrait to lock the orientation to portrait.
BaseConstructL(EAppOrientationLandscape);
}
Option 2:
The UI is already constructed and the orientation lock must be applied afterwards. This option works similarly as is done in Qt implementations.
#include <eikappui.h>
#include <aknenv.h>
#include <aknappui.h>
// Place this code to appropriate function / method
CAknAppUi* appUi = dynamic_cast<CAknAppUi*> (CEikonEnv::Static()->AppUi());
TRAPD(error,
if (appUi) {
// Lock application orientation into landscape,
// similarly use CAknAppUi::EAppUiOrientationPortrait
// to lock the orientation to portrait.
appUi->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
}
);
// ...
Postconditions
The application orientation is locked to landscape, and it does not change even if the device orientation is changed by the user.


(no comments yet)