1e41f4b71Sopenharmony_ci# Screen Rotation Animation Enhancement 2e41f4b71Sopenharmony_ci 3e41f4b71Sopenharmony_ciYou can add fade-in and fade-out transition effects to a screen rotation animation, to create a seamless transition experience. 4e41f4b71Sopenharmony_ci 5e41f4b71Sopenharmony_ciBelow is the complete sample code and effect. 6e41f4b71Sopenharmony_ci 7e41f4b71Sopenharmony_ci```ts 8e41f4b71Sopenharmony_ci// xx.ets 9e41f4b71Sopenharmony_ciimport { display } from '@kit.ArkUI'; 10e41f4b71Sopenharmony_ci 11e41f4b71Sopenharmony_ci@Entry 12e41f4b71Sopenharmony_ci@Component 13e41f4b71Sopenharmony_cistruct rotation { 14e41f4b71Sopenharmony_ci @StorageLink('orientation') myOrientation: display.Orientation = display.Orientation.PORTRAIT; 15e41f4b71Sopenharmony_ci 16e41f4b71Sopenharmony_ci build() { 17e41f4b71Sopenharmony_ci Stack() { 18e41f4b71Sopenharmony_ci if (this.myOrientation == display.Orientation.PORTRAIT || this.myOrientation == display.Orientation.PORTRAIT_INVERTED) { 19e41f4b71Sopenharmony_ci Image($r('app.media.sky')) 20e41f4b71Sopenharmony_ci .size({ width: 100, height: 100 }) 21e41f4b71Sopenharmony_ci .id('image1') 22e41f4b71Sopenharmony_ci } else { 23e41f4b71Sopenharmony_ci Image($r('app.media.tree')) 24e41f4b71Sopenharmony_ci .position({ x: 0, y: 0 }) 25e41f4b71Sopenharmony_ci .size({ width: 200, height: 200 }) 26e41f4b71Sopenharmony_ci .id('image2') 27e41f4b71Sopenharmony_ci } 28e41f4b71Sopenharmony_ci } 29e41f4b71Sopenharmony_ci .backgroundColor(Color.White) 30e41f4b71Sopenharmony_ci .size({ width: '100%', height: '100%' }) 31e41f4b71Sopenharmony_ci } 32e41f4b71Sopenharmony_ci} 33e41f4b71Sopenharmony_ci``` 34e41f4b71Sopenharmony_ci 35e41f4b71Sopenharmony_ciIn the **EntryAbility.ets** file, add processing logic to the **onWindowStageCreate** method to obtain the screen display orientation. 36e41f4b71Sopenharmony_ci```ts 37e41f4b71Sopenharmony_cionWindowStageCreate(windowStage: window.WindowStage): void { 38e41f4b71Sopenharmony_ci // Main window is created, set main page for this ability 39e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'Ability onWindowStageCreate'); 40e41f4b71Sopenharmony_ci 41e41f4b71Sopenharmony_ci let mainWindow: window.Window; 42e41f4b71Sopenharmony_ci try { 43e41f4b71Sopenharmony_ci mainWindow = windowStage.getMainWindowSync(); 44e41f4b71Sopenharmony_ci let displayClass: display.Display = display.getDefaultDisplaySync(); 45e41f4b71Sopenharmony_ci AppStorage.setOrCreate('orientation', displayClass.orientation); 46e41f4b71Sopenharmony_ci // Listen for the windowsSizeChange event, which is triggered when the screen is rotated. 47e41f4b71Sopenharmony_ci mainWindow.on('windowSizeChange', (data) => { 48e41f4b71Sopenharmony_ci console.info('Succeeded in enabling the listener for window size changes. Data: ' + JSON.stringify(data)); 49e41f4b71Sopenharmony_ci let displayClass: display.Display | null = null; 50e41f4b71Sopenharmony_ci try { 51e41f4b71Sopenharmony_ci displayClass = display.getDefaultDisplaySync(); 52e41f4b71Sopenharmony_ci console.info('display orientation is ' + JSON.stringify(displayClass.orientation)); 53e41f4b71Sopenharmony_ci // Obtain the screen display orientation. 54e41f4b71Sopenharmony_ci AppStorage.set('orientation', displayClass.orientation); 55e41f4b71Sopenharmony_ci } catch { 56e41f4b71Sopenharmony_ci return; 57e41f4b71Sopenharmony_ci } 58e41f4b71Sopenharmony_ci }) 59e41f4b71Sopenharmony_ci } catch { 60e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', '%{public}s', 'error'); 61e41f4b71Sopenharmony_ci return; 62e41f4b71Sopenharmony_ci } 63e41f4b71Sopenharmony_ci 64e41f4b71Sopenharmony_ci windowStage.loadContent('pages/Index', (err) => { 65e41f4b71Sopenharmony_ci if (err.code) { 66e41f4b71Sopenharmony_ci hilog.error(0x0000, 'testTag', 'Failed to load the content. Cause: %{public}s', JSON.stringify(err) ?? ''); 67e41f4b71Sopenharmony_ci return; 68e41f4b71Sopenharmony_ci } 69e41f4b71Sopenharmony_ci hilog.info(0x0000, 'testTag', 'Succeeded in loading the content.'); 70e41f4b71Sopenharmony_ci }); 71e41f4b71Sopenharmony_ci} 72e41f4b71Sopenharmony_ci``` 73e41f4b71Sopenharmony_ci 74e41f4b71Sopenharmony_ciIn the **module.json5** file of the project, add **orientation** to the **abilities** list and set the ability to **auto_rotation**. 75e41f4b71Sopenharmony_ci```json 76e41f4b71Sopenharmony_ci"orientation": "auto_rotation", 77e41f4b71Sopenharmony_ci``` 78e41f4b71Sopenharmony_ci 79e41f4b71Sopenharmony_ci 80