Change screen orientation of UI application
Article Metadata
The following example shows how to change the screen orientation of an S60 UI application, from portrait to landscape or vice-versa.
The method that is used to do the rotation is CAknAppUiBase::SetOrientationL(). There is also another method to get the current screen orientation, CAknAppUiBase::Orientation().
The following example shows a method that will change the orientation to portrait if the current one is landscape and vice-versa.
void CMyClass::RotateMe()
{
// Changing from portrait to landscape or vice versa.
iIsPortrait = !iIsPortrait;
// Change the screen orientation.
if (iIsPortrait)
{
AppUi()->SetOrientationL(CAknAppUi::EAppUiOrientationPortrait);
}
else
{
AppUi()->SetOrientationL(CAknAppUi::EAppUiOrientationLandscape);
}
}
If the application wants just be in a single UI orientation then it should use the CAknAppUI flags to force certain orientation: EAppOrientationPortrait or EAppOrientationLandscape.
CMyAppUi::ConstructL ()
{
BaseConstructL (EAknEnableSkin|EAppOrientationLandscape);
//...
}
Note: The flags are names and defined differently to those used in SetOrientationL. SetOrientationL e.g. uses EAppUiOrientationPortrait whereas CAknAppUI flag for the same orientation is EAppOrientationPortrait. This is error prone and has created lot of confusion as developers do not realized the slight naming difference.
Internal links
- Scalable UI
- Layout-awareness challenges in custom UIs
- How to find out the correct location for softkey labels
- How to get the Current Orientation




18 Sep
2009
Sometimes our application need the screen to orient in landscape orientation. The article presnts the code to chand the screen orientation of S60 user Interface application from potrait to landscape and vice-versa. The code is simple and made more easy with comments.
The article can be useful to intermediate developes who needs to change screen orientation in their application.
23 Sep
2009
Yes, CAknAppUiBase::SetOrientationL() is important API to set orientation of application. Beginners may find hard to set orientation and thus this article is very important for beginners.
Also note that you can set orientation of your application using CAknAppUiBase::SetOrientationL() API, not orientation of your device.