UIScrollview touchesbegan,touchesmoved,touchesended actions

会有一股神秘感。 提交于 2020-01-01 06:28:38

问题


I did this touch actions in UIView, ie, in a uiview there are two or three subviews v1,v2,v3. I used the code below to place the image i1,i2,i3 in corresponding views and if I moves the touch the images move to that point in the view.

- (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;
    }
}

Now I have to do this for a sequence of 28 images so I went for Uiscrollview but I cant get that please explain me clearly with code. thanks a lot in advance for your help.


回答1:


You need to subclass UIScrollView to get touch events of UIScrollView.



来源:https://stackoverflow.com/questions/6660327/uiscrollview-touchesbegan-touchesmoved-touchesended-actions

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!