屏幕外时关闭可拖动视图-iOS

时间:2018-08-30 07:47:19

标签: ios objective-c view draggable uipangesturerecognizer

我有一个可拖动的视图,当用户将其拖出屏幕时,我想关闭它。 因此,我编写了以下代码,但对我而言不起作用:

#pragma mark - View draggable method

- (void)detectPan:(UIPanGestureRecognizer *) uiPanGestureRecognizer
{
    CGPoint translation = [uiPanGestureRecognizer translationInView:self.view.superview];
    self.view.center = CGPointMake(lastLocation.x + translation.x,
                                              lastLocation.y + translation.y);

    CGRect temp = self.view.frame;
    temp.origin.x = [[UIScreen mainScreen] bounds].size.width ;
    [UIView animateWithDuration:2
                          delay:0.0
                        options: UIViewAnimationCurveEaseOut
                     animations:^{
                         self.view.frame = temp;
                     }completion:^(BOOL finished){
                         [self.view removeFromSuperview];
                     }];
}

- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
    [self.view.superview bringSubviewToFront:self.view];
    lastLocation = self.view.center;
}

我怎么了?

0 个答案:

没有答案