カスタムView
記事
IT・テクノロジー
Import
from ui import View
定義
class カスタムビュー(View):
def イベントメソッド(self):
処理
イベントメソッド
UIファイルで定義された属性が設定される前に実行される
def __init__(self):
Viewがすべて読み込まれてから実行される
def did_load(self):
※ add_subview()で追加したビューでは呼び出されないので
__init__()の最後で呼び出す
Viewが閉じる前に実行される
def will_close(self):
※ remove_subview()で削除したビューでは呼び出されないので
remove_subview()の前に呼び出す
タッチされたら実行される
def touch_began(self, touch):
スワイプ
def touch_began(self, touch):
self.start_pos = touch.location
def touch_ended(self, touch):
end_pos = touch.location
dx = end_pos[0] - self.start_pos[0]
dy = end_pos[1] - self.start_pos[1]
if 座標判定:
スワイプの処理
長押し
def touch_began(self, touch):
self.start_time = time.time()
def touch_ended(self, touch):
end_time = time.time()
duration = end_time - self.start_time
if タッチ時間の判定:
長押しの処理
ビューをカスタムViewにする
GUIで設定
①.pyuiファイル で View を選択
②i アイコン
③Custom View Class に カスタムViewのクラス名を入力