Ios 如何在Xcode中拖动UiScrollView中的图像。

Ios 如何在Xcode中拖动UiScrollView中的图像。,ios,objective-c,uiscrollview,Ios,Objective C,Uiscrollview,我创建了一个滚动视图,并在其中添加了一些图像 但现在,我不能将图像拖到scrollview之外 我犯了什么错 我参考了一些教程 但我不知道如何继续 我的代码: scroll =[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height * 0.9)]; scroll.pagingE

我创建了一个滚动视图,并在其中添加了一些图像

但现在,我不能将图像拖到scrollview之外

我犯了什么错

我参考了一些教程

但我不知道如何继续

我的代码

scroll =[[UIScrollView alloc]initWithFrame:CGRectMake(x, y, [UIScreen mainScreen].bounds.size.width, [UIScreen mainScreen].bounds.size.height * 0.9)];

    scroll.pagingEnabled=YES;

    scroll.scrollEnabled = TRUE;
    [scroll setBackgroundColor:[UIColor redColor]];

    scroll.bounces=TRUE;
    scroll.userInteractionEnabled=YES;

    scroll.showsHorizontalScrollIndicator=TRUE;

    [scroll setContentSize:CGSizeMake(3500, sh)];

    [self.view addSubview:scroll];

    for (int i=1; i <= 6; i++) {


        NSString *imageName = [NSString stringWithFormat:@"img%d.jpg", i];
        UIImage *image = [UIImage imageNamed:imageName];
        imageView = [[UIImageView alloc] initWithImage:image];

        CGRect rect = imageView.frame;
        rect.origin.x = currentX;
        rect.size.height=[UIScreen mainScreen].bounds.size.height * 0.9;
        rect.size.width=width/4;
        imageView.frame = rect;

        currentX += imageView.frame.size.width;
        currentX += 30;

        [scroll addSubview:imageView];

    }

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    if ([touches count] == 1) {

        CGPoint touchPoint = [[touches anyObject] locationInView:self.view];
        for (UIImageView *iView in self.view.subviews) {

            if ([iView isMemberOfClass:[UIImageView class]]) {

                if (touchPoint.x > iView.frame.origin.x &&
                    touchPoint.x < iView.frame.origin.x + iView.frame.size.width &&
                    touchPoint.y > iView.frame.origin.y &&
                    touchPoint.y < iView.frame.origin.y + iView.frame.size.height)
                {

                    self.sizePosition=CGPointMake(iView.frame.size.width, iView.frame.size.height);

                    self.dragObject = iView;
                    self.touchOffset = CGPointMake(touchPoint.x - iView.frame.origin.x,
                                                   touchPoint.y - iView.frame.origin.y);

                    self.homePosition = CGPointMake(iView.frame.origin.x,
                                                    iView.frame.origin.y);

                    [self.view bringSubviewToFront:self.dragObject];

                    self.sizebig=CGPointMake(iView.frame.size.width+20,iView.frame.size.height+25);
                }
            }
        }
    }
}
- (void)touchesMoved:(NSSet *)touches withEvent:(UIEvent *)event
{

    CGPoint touchPoint = [[touches anyObject] locationInView:self.view];

    CGRect newDragObjectFrame = CGRectMake(touchPoint.x - touchOffset.x,
                                           touchPoint.y - touchOffset.y,
                                           self.sizebig.x,
                                           self.sizebig.y);


    self.dragObject.frame = newDragObjectFrame;
}

- (void)touchesEnded:(NSSet *)touches withEvent:(UIEvent *)event
{

    CGPoint touchPoint = [[touches anyObject] locationInView:self.view];

    if (touchPoint.x > self.dropTarget.frame.origin.x &&
        touchPoint.x < self.dropTarget.frame.origin.x + self.dropTarget.frame.size.width &&
        touchPoint.y > self.dropTarget.frame.origin.y &&
        touchPoint.y < self.dropTarget.frame.origin.y + self.dropTarget.frame.size.height )
    {

        self.droptargett.image=self.dragObject.image;

    }

    self.dragObject.frame = CGRectMake(self.homePosition.x,self.homePosition.y,sizePosition.x,sizePosition.y);
}
scroll=[[UIScrollView alloc]initWithFrame:CGRectMake(x,y,[UIScreen mainScreen].bounds.size.width,[UIScreen mainScreen].bounds.size.height*0.9)];
scroll.PaginEnabled=是;
scroll.scrollEnabled=TRUE;
[滚动设置背景颜色:[UIColor REDCLOR]];
滚动。反弹=真;
scroll.userInteractionEnabled=YES;
scroll.showshorizontalscrolindicator=TRUE;
[滚动设置contentsize:CGSizeMake(3500,sh)];
[self.view addSubview:滚动];
对于(int i=1;i iView.frame.origin.x&&
接触点.xiView.frame.origin.y&&
接触点.yself.dropTarget.frame.origin.x&&
接触点.xself.dropTarget.frame.origin.y&&
接触点.y