UITableViewCell
состоит из backgroundView
и contentView
, которая лежит над backgroundView
, что вы можете сделать, это добавить UIButton
с, как subView
с к вашему backgroundView
и добавить UIPanGestureRecognizer
на ячейку. Поэтому, когда вы поворачиваете ячейку по горизонтали, только contentView
перемещается, UIButton
s подвергается воздействию. Таким образом, в cellForRowAtIndexPath
-(UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath
{
UITableViewCell *myCell;
myCell=[[UITableViewCell alloc]initWithStyle:UITableViewCellStyleValue1 reuseIdentifier:@"YOUR_IDENTIFIER"];
//adding button to a view that is added as the backgroundview
UIView *cellBackgroundUtilityView=[[UIView alloc]initWithFrame:myCell.frame];
[cellBackgroundUtilityView addSubview:<your button>]
[myCell setBackgroundView: cellBackgroundUtilityView]
//adding a gesture recognizer
UIPanGestureRecognizer *panningCell=[[UIPanGestureRecognizer alloc]initWithTarget:self action:@selector(yourPanningTableViewCellMethod:)];
[panningCell setDelegate:self];
[myCell addGestureRecognizer:panningCell];
}
, когда жест распознаватель будет активен этот метод будет называться
-(void) yourPanningTableViewCellMethod:(id)sender
{
// gesture recognizer is active
UIPanGestureRecognizer* recognizer=(UIPanGestureRecognizer *) sender;
UITableViewCell *tableCell=(UITableViewCell *)recognizer.view;
//moving the contentView horizontally according to pan
[tableCell.contentView setFrame:CGRectMake([recognizer translationInView:self.view].x, tableCell.contentView.frame.origin.y, tableCell.frame.size.width, tableCell.frame.size.height)];
}
когда селектор кнопки называется
-(void)yourBackgroundViewButtonWasPressed
{
// button was pressed
// move content view of the cell back to origin
[tableCell.contentView setFrame:CGRectMake(0.0, tableCell.contentView.frame.origin.y, tableCell.frame.size.width, tableCell.frame.size.height)];
//do your stuff
}