相关疑难解决方法(0)

iPhone SDK:麻烦拖动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"的用户交互设置为启用,则图像不再可拖动,但是当它未设置为启用时它是.

iphone xcode draggable touch uiimageview

5
推荐指数
1
解决办法
7490
查看次数

标签 统计

draggable ×1

iphone ×1

touch ×1

uiimageview ×1

xcode ×1