Sam*_*Sam 5 iphone xcode draggable touch uiimageview
我试图在我的应用程序中围绕iphone屏幕拖动UIImageView.
目前我设置的拖动功能很好,拖动图像确实会在屏幕上移动它,麻烦的是你不必拖动图像视图来移动它,你也可以拖动到屏幕上的任何地方它会移动图像.我是这个平台的新手,所以我无法真正思考如何解决这个问题.我当前拖动图片的代码是:
- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:pig];
startLocation = pt;
}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:pig];
CGRect frame = [pig frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[pig setFrame: frame];
}
Run Code Online (Sandbox Code Playgroud)
任何帮助赞赏.顺便说一下,猪是UIImageView.另外我注意到,如果我将图像视图"pig"的用户交互设置为启用,则图像不再可拖动,但是当它未设置为启用时它是.
您可以尝试子类化 UIImageView 并直接在其上实现touchesBegan:和。touchesMoved:然后在 InterfaceBuilder 中选择 UIImageView 的子类。
替代文本 http://img.skitch.com/20090728-xetretcfubtcj7ujh1yc8165wj.jpg
哦,是的,现在您需要再次设置用户交互......
| 归档时间: |
|
| 查看次数: |
7490 次 |
| 最近记录: |