iPhone開發高階(8) 檢測螢幕觸控事件

2021-05-25 07:15:58 字數 893 閱讀 8152

這一回來定製 uiview 上的觸控事件,作為例子,只是簡單地檢測出觸控事件並顯示當前座標在控制台上。

首先新增新檔案,如下圖:

在顯示的對話方塊中選中 cocoa touch class 的 objective c class ⇒ uiview

在專案的新增選單中選擇 touch 。檢測觸控時間需要實現下面的函式。

1

2

- (void)touchesbegan

:(nsset*)touches

withevent

:(uievent*)event;

這個函式由使用者觸控螢幕以後立刻被調到。為了自定義他的行為,我們像下面來實現:

123

45

- (void)touchesbegan

:(nsset*)touches

withevent

:(uievent*)event

上面的**將觸控點的座標取出,並列印到控制台上。

如果需要得到多點觸控(不只是一根手指)的資訊,需要使用 anyobject 例項指定 uiview。

123

4567

8

- (void
這裡用 intiwithframe 指定的矩形區域可以任意。另外為了明確觸控的區域大小,設定其 view.backgroundcolor。

開發支援iPhone橫屏的Tab Bar程式

override to allow orientations other than the default portrait orientation.bool shouldautorotatetointe ceorientation uiinte ceorientation inte ceorien...

iOS開發之應用內檢測手機鎖屏,解鎖狀態

1.程式在前台,這種比較簡單。直接使用darwin層的通知就可以了 import staticvoidscreenlockstatechanged cfnotificationcenterrefcenter,void observer,cfstringrefname,constvoid object...

iOS開發 檢測程式在前台和後台鎖屏解鎖的狀態

1 程式在前台判斷是否鎖屏或解鎖。判斷方法 直接使用darwin層的通知就可以。import define notificationlock cfstr define notificationchange cfstr define notificationpwdui cfstr static voi...