Titanium で View が端末に表示されたときになにか処理を行う方法

More than 1 year has passed since last update.

View が表示されてから実施したい処理がありました.

postlayout イベントに処理を愚直に書いたら大変なことになった

postlayout という名前と,ドキュメントの1行目だけ読んでなんとなくいけそーだなーと思って,alertでも仕込んでみたら大変なことになりました.(Nexus5 が再起動しました)

postlayout についてのドキュメントの記載は...

Fired when a layout cycle is finished.

This event is fired when the view and its ancestors have been laid out. The rect and size values should be usable when this event is fired.

This event is typically triggered by either changing layout properties or by changing the orientation of the device. Note that changing the layout of child views or ancestors can also trigger a relayout of this view. On Mobile Web, this event can also be triggered by resizing the browser window.

Note that altering any properties that affect layout from the postlayout callback may result in an endless loop.




$.hogehoge.addEventListener('postlayout', function(){
    // なにかの処理

    // postlayout のリスナーを全部消す
    $.hogehoge.removeEventListener('postlayout', arguments.callee);




Sign up for free and join this conversation.
Sign Up
If you already have a Qiita account log in.