左にスライドするとSideSwipeView
a を置き換えるビューがあります。UITableViewCell
がSideSwipeView
表示されると、 内に 6 つのボタンが表示されるはずSideSwipeView
です。6 つのボタンが表示されますが、正しい位置に配置されません。ビューの中央に配置するにはどうすればよいですか?
- (void) setupSideSwipeView
{
// Iterate through the button data and create a button for each entry
CGFloat leftEdge = BUTTON_LEFT_MARGIN;
for (NSDictionary* buttonInfo in buttonData)
{
// Create the button
UIButton* button = [UIButton buttonWithType:UIButtonTypeCustom];
// Make sure the button ends up in the right place when the cell is resized
button.autoresizingMask = UIViewAutoresizingFlexibleRightMargin | UIViewAutoresizingFlexibleLeftMargin | UIViewAutoresizingFlexibleBottomMargin | UIViewAutoresizingFlexibleTopMargin;
// Get the button image
UIImage* buttonImage = [UIImage imageNamed:[buttonInfo objectForKey:@"image"]];
// Set the button's frame
button.frame = CGRectMake(leftEdge, sideSwipeView.center.y - buttonImage.size.height/2.0, buttonImage.size.width, buttonImage.size.height);
// Add the image as the button's background image
// [button setBackgroundImage:buttonImage forState:UIControlStateNormal];
UIImage* grayImage = [self imageFilledWith:[UIColor colorWithWhite:0.9 alpha:1.0] using:buttonImage];
[button setImage:grayImage forState:UIControlStateNormal];
// Add a touch up inside action
[button addTarget:self action:@selector(touchUpInsideAction:) forControlEvents:UIControlEventTouchUpInside];
// Keep track of the buttons so we know the proper text to display in the touch up inside action
[buttons addObject:button];
// Add the button to the side swipe view
[self.sideSwipeView addSubview:button];
// Move the left edge in prepartion for the next button
leftEdge = leftEdge + buttonImage.size.width + BUTTON_SPACING;
}
}
右または左スワイプの方法。この方法は、代わりにwith とswipeLeft
ほぼ同じです。swipeRight
UISwipeGestureRecognizerDirectionLeft
UISwipeGestureRecognizerDirectionRight
// Called when a right swipe occurred
- (void)swipeRight:(UISwipeGestureRecognizer *)recognizer
{
[self swipe:recognizer direction:UISwipeGestureRecognizerDirectionRight];
}
// Handle a left or right swipe
- (void)swipe:(UISwipeGestureRecognizer *)recognizer direction:(UISwipeGestureRecognizerDirection)direction
{
if (recognizer && recognizer.state == UIGestureRecognizerStateEnded)
{
// Get the table view cell where the swipe occured
CGPoint location = [recognizer locationInView:self.tableView];
NSIndexPath* indexPath = [self.tableView indexPathForRowAtPoint:location];
UITableViewCell* cell = [self.tableView cellForRowAtIndexPath:indexPath];
// If we are already showing the swipe view, remove it
if (cell.frame.origin.x != 0)
{
[self removeSideSwipeView:YES];
return;
}
// Make sure we are starting out with the side swipe view and cell in the proper location
[self removeSideSwipeView:NO];
// If this isn't the cell that already has thew side swipe view and we aren't in the middle of animating
// then start animating in the the side swipe view
if (cell!= sideSwipeCell && !animatingSideSwipe)
[self addSwipeViewTo:cell direction:direction];
}
}