Закрыть перетаскиваемый вид, когда его нет на экране - PullRequest
0 голосов
/ 30 августа 2018

У меня перетаскиваемый вид, и я хочу закрыть его, когда пользователь перетаскивает его за пределы экрана. По этой причине я написал этот код, но он не работает для меня:

#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;
}

Что я не прав?

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...