开发者

How to duplicate rendering of DELETE button on UITableViewCell Swipe for a UISwipeGestureRecognizer?

Basically I have created a UISwipeGestureRecognizer for my UITableView for when the user swipes from left to right. When the user swipes right to left, the DELETE renders and functions as it should.

I'm trying to get a new custom UIButton to render exactly the same way the DELETE button renders when swiped. It doesn't slide in but sort of slowly reveals itself from right to left?

I would like to do this for my custom UIButton to appear in the same place as DELETE except this time only when the user swipes right to left.

I have this method set as the @selector after a swipe has been detected right to left:

- (void)displayAddArchiveView:(UIGestureRecognizer *)gest开发者_如何学GoureRecognizer {
    // Assume this is the view container that will contain my UIButton
    GreenGradientView *archiveView = [[GreenGradientView alloc] initWithFrame:CGRectMake(211.0, 3.0, 63.0, 30.0)];

    if (gestureRecognizer.state == UIGestureRecognizerStateEnded) {
       CGPoint swipeLocation = [gestureRecognizer locationInView:self.reportsTableView];
       NSIndexPath *swipedIndexPath = [self.reportsTableView indexPathForRowAtPoint:swipeLocation];
       ReportsTableViewCell *swipedCell = (ReportsTableViewCell *)[self.reportsTableView cellForRowAtIndexPath:swipedIndexPath];

      [self tableView:reportsTableView willBeginEditingRowAtIndexPath:swipedIndexPath];

      // HERE I should do some sort of UIView animation block to slowly reveal it 
      // from the right to left or something? Any suggestions. Not sure how to go about it?
      [swipedCell addSubview:archiveView];
    }
}

I have indicated by comments inside the code block my thoughts. The custom UIView actually does show up after swiping so I know it works. It's just a matter of getting the animation right, identical to how the DELETE button reveals itself? Suggestions?

Thanks!


You could try something like this

    CGRect finalFrame = archiveView.frame;
    archiveView.frame = CGRectMake(finalFrame.origin.x + finalFrame.size.width, finalFrame.origin.y, 0, finalFrame.size.height);
    [UIView animateWithDuration:0.3 animations:^{
        archiveView.frame = finalFrame;
    }];

Basically I've reset the frame so it has no width and set the origin on the far right (so that it grows from the right towards the left). Then in the animation block, i set the frame to what I want it to be at the end. In your case you can just save the final frame in a local variable before you reset the frame to have zero width.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜