У меня перетаскиваемый вид, и я хочу закрыть его, когда пользователь перетаскивает его за пределы экрана.
По этой причине я написал этот код, но он не работает для меня:
#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;
}
Что я не прав?