我有UIScrollView包含許多UIImageViews。我需要從UIScrollView拖動UIImage到另一個視圖。但是我的代碼只在UIScrollView中拖動。我無法將圖像拖到scrollView之外。請幫我..我的代碼..從UIScrollView拖動UIImageView到另一個視圖
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];
}
嗯有趣的問題。嘗試setClipsToBounds:NO滾動視圖,看看它是否有所作爲。 – 2013-02-26 15:17:56
在編碼之前,您希望應用程序知道用戶意圖在拖動其中一個子視圖和拖動以滾動之間的差異?也許使用兩個手指拖動拖動子視圖? – danh 2013-02-26 15:38:30
@EgeAkpinar如果關閉裁剪,即使這種方式有效,也會產生問題,因爲一旦它關閉了滾動視圖,大概不希望它隨着滾動視圖的滾動而移動。底線,你只是想從滾動視圖中刪除它,並將其添加到您要刪除它的視圖。 – Rob 2013-02-26 15:39:44