【发布时间】:2010-04-16 20:58:15
【问题描述】:
我想在其上使用 UIview 和 UIImage 以及文本框和按钮我希望用户在触摸 UIview 或视图中的任何内容时拖动它,实现此方法的最佳方法是什么?
UIView 位于单个 View Controller 上,并使用 Interface Builder 制作我的 UIviews 和 UIimages。
【问题讨论】:
标签: iphone objective-c
我想在其上使用 UIview 和 UIImage 以及文本框和按钮我希望用户在触摸 UIview 或视图中的任何内容时拖动它,实现此方法的最佳方法是什么?
UIView 位于单个 View Controller 上,并使用 Interface Builder 制作我的 UIviews 和 UIimages。
【问题讨论】:
标签: iphone objective-c
查看 Apple 示例“MoveMe”http://developer.apple.com/iphone/library/samplecode/MoveMe/Introduction/Intro.html
里面的MoveMeView类是可拖动的。 (还有一些多余的动画在进行,但拖动是有的)。
【讨论】:
你需要继承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.
【讨论】: