如何使用UIimage ontop检测UIView上的触摸?
问题描述:
我想用一个文本框和按钮来使用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在那里可拖动。 (还有一些多余的动画正在进行,但拖动就在那里)。