【问题标题】:How to make a UIImageView draggable?如何使 UIImageView 可拖动?
【发布时间】:2013-09-23 22:48:39
【问题描述】:

我是一名初学者 iOS 开发人员,我正在尝试制作一个应用程序,让用户在屏幕上移动图像(实际上是拖动图像)。有人可以帮我解决这个问题吗?我还希望用户不能将图像拖出屏幕。谢谢! 我在 UIImageView 的子类中尝试了以下代码:

- (void) touchesBegan:(NSSet*)touches withEvent:(UIEvent*)event {
    CGPoint pt = [[touches anyObject] locationInView:self];
    startLocation = pt;
    [[self superview] bringSubviewToFront:self];

}
- (void) touchesMoved:(NSSet*)touches withEvent:(UIEvent*)event {
CGPoint pt = [[touches anyObject] locationInView:self];
CGRect frame = [self frame];
frame.origin.x += pt.x - startLocation.x;
frame.origin.y += pt.y - startLocation.y;
[self setFrame: frame];
}

它在使用起始位置的三行中显示错误(“使用未声明的标识符'startLocation'”)。有人可以帮我解决这个错误吗?

【问题讨论】:

  • 你有没有尝试实现任何东西?如果是这样,请分享代码。
  • 刚刚编辑了我的问题。

标签: uiimageview draggable


【解决方案1】:

知道了,我只需要在方法之前声明它。

【讨论】:

    猜你喜欢
    • 2023-04-05
    • 1970-01-01
    • 1970-01-01
    • 2014-08-13
    • 1970-01-01
    • 2011-06-26
    • 1970-01-01
    • 2012-05-25
    • 1970-01-01
    相关资源
    最近更新 更多