Iphone 当Im移动从cloudScrollView中拾取的视图时,未在前面显示拾取的视图
在Iphone 当Im移动从cloudScrollView中拾取的视图时,未在前面显示拾取的视图,iphone,uiview,uipangesturerecognizer,Iphone,Uiview,Uipangesturerecognizer,在UIScrollView上添加UIImageView,并向其添加UIPangestureRecognitor UIImageView* lbl = [[UIImageView alloc]init]; NSString* tempStr = [NSString stringWithFormat:@"images/%@",[self.cloudArray objectAtIndex:i]]; NSString* imgPath = [self appendDocumentDirectoryPat
UIScrollView
上添加UIImageView
,并向其添加UIPangestureRecognitor
UIImageView* lbl = [[UIImageView alloc]init];
NSString* tempStr = [NSString stringWithFormat:@"images/%@",[self.cloudArray objectAtIndex:i]];
NSString* imgPath = [self appendDocumentDirectoryPath:tempStr];
lbl.image = [[[UIImage alloc] initWithContentsOfFile:imgPath] autorelease];
[lbl setUserInteractionEnabled:YES];
//add gestures
UIPanGestureRecognizer *panGesture = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(moveImage:)];
[panGesture setMinimumNumberOfTouches:1];
[panGesture setMaximumNumberOfTouches:1];
[lbl addGestureRecognizer:panGesture];
[panGesture release];
CGSize expectedLabelSize = CGSizeMake(150, height);
lbl.frame = CGRectMake(pntX, pntY, expectedLabelSize.width, height);
[rectFrame addObject:[NSValue valueWithCGRect:lbl.frame]];
lbl.tag = i;
[cloudScrollView addSubview:lbl];
[lbl release];
lbl = nil;
pntX = pntX + space + expectedLabelSize.width;
[cloudScrollView setContentSize:CGSizeMake([cloudArray count]*170, 160)];
#pragma mark METHOD TO CATCH MOVE GESTURE EVENTS
- (void)moveImage:(UIPanGestureRecognizer *)gesture
{
if (gesture.state == UIGestureRecognizerStateChanged) {
location1 = [gesture locationInView:cloudScrollView];
view1 = [gesture view];
if (isFirstTime) {
isFirstTime = NO;
draggedTag = view1.tag;
}
[view1 setCenter:CGPointMake(location1.x, location1.y)];
}
if (gesture.state == UIGestureRecognizerStateEnded) {
CGPoint pnt = [gesture locationInView:customTableView];
NSIndexPath* indexPath = [customTableView indexPathForRowAtPoint:pnt];
NSLog(@"indexpath = %d",indexPath.row);
if (index >= 0) {
[self.ansArray replaceObjectAtIndex:indexPath.row withObject:[self.cloudArray objectAtIndex:draggedTag]];//[self.cloudArray objectAtIndex:draggedTag]
[customTableView reloadData];
}
CGRect draggedItemRect = [[rectFrame objectAtIndex:draggedTag] CGRectValue];
view1.frame = draggedItemRect;
isFirstTime = YES;
}
}
删除
lbl=nil
。您想拖动imageView还是只想更改imageView在scrollview上的位置???您好,我想拖动imageView。imageView是否正在移动??如果它正在移动,请放入[cloudScrollView bringSubviewToFront:view1]
。它正在移动,但不显示在前面。如果我在UIView上添加UIImageview,它将显示在前面,但我希望视图可以滚动。因此,我在UIscrollView上添加了UIImageView,但当我拖动视图时,它在前面不可见,它希望它们在前面。