English 中文(简体)
从UITableView拖动按钮
原标题:Dragging a button from UITableView

我有一个由自定义单元格组成的TableView。此单元格包含一个标签和一个按钮。现在,我在单元格中的按钮中添加了一个panGestureRecognizer 我的问题是,当我尝试开始移动/拖动按钮时,按钮会正确移动,但不幸的是,按钮会隐藏在TableView后面。我该如何让它出现在它前面。自定义单元格是通过编程创建的,TableView也是如此。我的手势处理方法如下:


-(void)panPiece:(UIPanGestureRecognizer *)gestureRecognizer withEvent:(id) event {
UIView *piece = [gestureRecognizer view];
[self adjustAnchorPointForGestureRecognizer:gestureRecognizer];

//*******************Dragging Ended*************************************

if([gestureRecognizer state]==UIGestureRecognizerStateEnded)
{
    [tableView scrollToRowAtIndexPath:[NSIndexPath indexPathForRow:0 inSection:0] atScrollPosition:UITableViewScrollPositionBottom animated:YES];

}

//*******************Dragging Started andchanged*************************************

if ([gestureRecognizer state] == UIGestureRecognizerStateBegan || [gestureRecognizer state] ==UIGestureRecognizerStateChanged) 
{

    CGPoint translation = [gestureRecognizer translationInView:[piece superview]];
    [piece setCenter:CGPointMake([piece center].x + translation.x, [piece center].y + translation.y)];
    [gestureRecognizer setTranslation:CGPointZero inView:[piece superview]];
    CGPoint moveLocation=[gestureRecognizer locationInView:piece];
    NSIndexPath *indexPath=[tableView indexPathForRowAtPoint:moveLocation];

}

-(void)adjustAnchorPointForGestureRecognizer:(UIGestureRecognizer *)gestureRecognizer { if (gestureRecognizer.state == UIGestureRecognizerStateBegan || (gestureRecognizer.state == UIGestureRecognizerStateChanged)) { UIView *piece = gestureRecognizer.view; CGPoint locationInView = [gestureRecognizer locationInView:piece]; CGPoint locationInSuperview = [gestureRecognizer locationInView:piece.superview]; piece.layer.anchorPoint = CGPointMake(locationInView.x / piece.bounds.size.width, locationInView.y / piece.bounds.size.height); piece.center = locationInSuperview; } }


The code has been modelled based on apple s code here
问题回答

这里是解决方案:将UIImageView从UIscrollView拖动到另一个视图

希望这能有所帮助





相关问题
Plist Hierarchy and All Option

I have a string of data in a plist, which I ve got to display, hierarchically like this: Menu>Chapter>SubChapter>item>item details This might be super simple, in my initial menu, how would I have ...

Disable iPhone table rows

Is there any way to disable the "selectibility" of a UITableView row? Example: I would like to make an appointment for a haircut at a certain time with a certain stylist. What gets displayed to a ...

Nonintrusive visual cue for uitableviewcell

I d like to mark a tableview row in some way that shows it has been clicked by the user. I have a large number of rows and want users to know if they have already visited a particular row. This same ...

TableView oval button for Index/counts

Can someone help me create an index/count button for a UITableView, like this one? iTunes http://img.skitch.com/20091107-nwyci84114dxg76wshqwgtauwn.preview.jpg Is there an Apple example, or other ...

Unable to pushViewController for subview

I have a UINavigationController and I have seperate UIViews that I switch between using a UISegmentControl. On switching the views, I add the view as a subview to my navigation controller s view: [...

热门标签