【发布时间】: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