0

我是一名初学者 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'”)。有人可以帮我解决这个错误吗?

4

1 回答 1

0

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

于 2013-09-24T19:59:41.917 回答