我想用一個文本框和按鈕來使用UIview和UIImage的ontop,我希望用戶在UIview或視圖中的任何內容被觸摸時拖動它,那麼實現此方法的最佳方式是什麼?如何使用UIimage ontop檢測UIView上的觸摸?
UIView在單個視圖控制器上,並使用界面生成器來製作我的UIviews和UIimages。
我想用一個文本框和按鈕來使用UIview和UIImage的ontop,我希望用戶在UIview或視圖中的任何內容被觸摸時拖動它,那麼實現此方法的最佳方式是什麼?如何使用UIimage ontop檢測UIView上的觸摸?
UIView在單個視圖控制器上,並使用界面生成器來製作我的UIviews和UIimages。
您需要繼承UIView
和實施
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
,
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
,
- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
,並
- (void)touchesCancelled:(NSSet *)touches withEvent:(UIEvent *)event
。
看一看蘋果樣品「MoveMe的」 http://developer.apple.com/iphone/library/samplecode/MoveMe/Introduction/Intro.html
類MoveMeView在那裏可拖動。 (還有一些多餘的動畫正在進行,但拖動就在那裏)。