我有 UIScrollView 包含许多 UIImageViews。我需要将 UIImage 从 UIScrollView 拖到另一个视图。但是我的代码仅在 UIScrollView 中拖动。我无法将图像拖动到 scrollView 之外。请帮助我..我的代码是..
for (int i = 0; i < [myArray count]; i++) {
image = [[UIImageView alloc]initWithFrame:CGRectMake(0, y, 75, 30)];
image.userInteractionEnabled = YES;
image.backgroundColor = [UIColor blueColor];
UIPanGestureRecognizer *panRecg = [[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(labelDragged:)];
[image addGestureRecognizer:panRecg];
y=y+35;
[gScrollView addSubview:image];
}
-(void)labelDragged:(UIPanGestureRecognizer *)recognizer {
UIImageView *imageView = (UIImageView *)recognizer.view;
CGPoint newCenter = [recognizer translationInView:self.view];
if([recognizer state] == UIGestureRecognizerStateBegan) {
beginX = imageView.center.x;
beginY = imageView.center.y;
}
newCenter = CGPointMake(beginX + newCenter.x, beginY + newCenter.y);
[imageView setCenter:newCenter];
}