UIScrollview涉及开始,触摸移动,触摸行动

时间:2011-07-12 06:31:25

标签: iphone objective-c uiscrollview

我在UIView中做了这个触摸操作,即 在uiview中有两个或三个子视图v1,v2,v3。我使用下面的代码将图像i1,i2,i3放在相应的视图中,如果我移动触摸,图像会移动到视图中的那个点。

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if ([touch view] == v1)
    {
        CGPoint location = [touch locationInView:v1];
        i1.center = location;
    }
        else if([touch view] == v2)
    {
        CGPoint location = [touch locationInView:v2];
        i2.center = location;
    }
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event {
    UITouch *touch = [touches anyObject];
    if ([touch view] == v1)
    {
        CGPoint location = [touch locationInView:v1];
        i1.center = location;
    }
        else if([touch view] == v2)
    {
        CGPoint location = [touch locationInView:v1];
        i2.center = location;
    }
}

现在我必须为28个图像序列执行此操作,所以我选择了Uiscrollview,但我不能得到它,请用代码清楚地解释我。非常感谢您的帮助。

1 个答案:

答案 0 :(得分:2)

您需要将UIScrollView子类化以获取UIScrollView的触摸事件。