我們有一個 Adob??e AIR 桌面應用程式。在視窗中有一個帶有一些按鈕的頂欄。中央按鈕始終在螢屏的水平中心打開一個下拉彈出視窗。以前沒有滾動條,頂部欄和彈出視窗始終水平對齊。但是現在我們引入了水平和垂直滾動條,因此當調整視窗大小時,頂部欄不在活動視窗的中心,因此它與彈出視窗不對齊。
請檢查圖片。頂欄——

彈出視窗 -

如果視窗在水平側最大化,則頂部欄和彈出視窗對齊。
現在是 mxml 代碼 -
public function showMainMenu():void
{
log.debug("Menu button clicked.");
if(animatingMenu)
{
log.debug("Suppressing showing of menu. Animation already in progress.");
return;
}
animatingMenu = true;
menuButton.visible = true;
mainMenu.visible = true;
PopUpManager.addPopUp(mainMenu, FlexGlobals.topLevelApplication as DisplayObject, true);
PopUpManager.centerPopUp(mainMenu);
mainMenu.y = -mainMenu.height menuButton.height;
mainMenu.refresh();
showMenuEffect.play();
menuButton.visible = false;
}
<fx:Declarations>
<menu:MainMenu id="mainMenu"/>
<s:Move id="showMenuEffect" target="{mainMenu}" yFrom="{-mainMenu.height menuButton.height}" yTo="-5" effectEnd="menuShowed(event)" duration="1200"/>
<s:Move id="hideMenuEffect" target="{mainMenu}" yFrom="-5" yTo="{-mainMenu.height menuButton.height}" effectEnd="menuHided(event)" duration="600"/>
</fx:Declarations>
<s:HGroup width="100%">
<s:VGroup horizontalAlign="center" width="100%" paddingLeft="{this.width / 2 - menuButton.width / 2}">
<s:Button id="menuButton" automationName="menuButtonShow" click="showMainMenu()" styleName="mainMenuButton" height="40" width="200"/>
</s:VGroup>
<s:HGroup horizontalAlign="right" width="100%" paddingRight="48" paddingTop="10">
<desktop:LocaleSelector id="localeSelector"/>
<desktop:ButtonCorner id="buttonCorner"/>
</s:HGroup>
<s:VGroup paddingRight="24" paddingTop="25" horizontalAlign="right">
<s:Button id="closeScreenButton" visible="false" styleName="closeScreenButton" width="29" height="35"/>
</s:VGroup>
</s:HGroup>
應該改變什么?我如何將頂欄始終定位在螢屏的中心。我應該創建 css 檔案來處理這種情況嗎?
uj5u.com熱心網友回復:
這是默認行為。當你顯示一個彈出視窗時,你告訴它在 .y 和 .x 中的位置。當您滾動或調整大小時,您有效地更改了視窗的“中心”,但您從未通知它它已更改。
我會嘗試添加一個偵聽器以調整視窗大小并onChange重新居中彈出視窗。
示例代碼(未經測驗,但應該可以作業):
var widthWatch:ChangeWatcher = ChangeWatcher.watch(this, 'widht', resizeHandler);
private var resizeExecuting:Boolean = false;
//this should run as soon as your app does (in most cases I do that in creationComplete or initialize())
private function onCreationComplete(event:Event):void
{
widthWatch = ChangeWatcher.watch(this,'width',onSizeChange);
}
//this checks if the resize stopped before actually moving the popup. Alternatively you can move your popup.center code here
private function onSizeChange(event:Event):void
{
if(!resizeExecuting)
callLater(handleResize);
resizeExecuting = true;
}
private function handleResize():void
{
PopUpManager.centerPopUp(mainMenu);
resizeExecuting = false;
}
轉載請註明出處,本文鏈接:https://www.uj5u.com/houduan/417756.html
標籤:
