Namespaces
Variants
Actions
Revision as of 08:11, 2 February 2012 by hamishwillee (Talk | contribs)
(diff) ← Older revision | Latest revision (diff) | Newer revision → (diff)

Change screen orientation of UI application

Jump to: navigation, search
Article Metadata

Article
Created: antonypr (25 Jun 2007)
Last edited: hamishwillee (02 Feb 2012)


The following example shows how to change the screen orientation of an S60 UI application, from portrait to landscape or vice-versa.


Rotate portrait.png Rotate landscape.png


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

External links

202 page views in the last 30 days.
Nokia Developer aims to help you create apps and publish them so you can connect with users around the world.

京ICP备05048969号  © Copyright Nokia 2013 All rights reserved