vie*_*one 13 uinavigationcontroller swipe ios ios7
我想标记我UINavigationController的动画(推/弹)或不是.
我有一个BOOL变量(_isAnimating),下面的代码似乎工作:
- (void)navigationController:(UINavigationController *)navigationController willShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
_isAnimating = YES;
}
- (void)navigationController:(UINavigationController *)navigationController didShowViewController:(UIViewController *)viewController animated:(BOOL)animated
{
_isAnimating = NO;
}
Run Code Online (Sandbox Code Playgroud)
但它在iOS7中使用滑动手势无法正常工作.假设我的导航是:root-> view A - > view B. 我现在在B.
在滑动开始时(从B回到A)navigationController:willShowViewController:animated:(BOOL)animated,然后调用函数" " _isAnimating = YES.
正常情况是滑动完成(返回A)navigationController:didShowViewController:animated:(BOOL)animated,然后调用函数" " _isAnimating = NO.这种情况没问题,但是:
如果用户可能只刷一半(半转换到A),然后不想滑动到上一个视图(视图A),他再次转到当前视图(再次保持B).然后navigationController:didShowViewController:animated:(BOOL)animated没有调用函数" ",我的变量值不正确(_isAnimating=YES).
在这种异常情况下,我没有机会更新我的变量.有没有办法更新导航状态?谢谢!
解决问题的线索可以在UINavigationController的InteractivePopGestureRecognizer属性中找到。这是通过滑动手势响应弹出控制器的识别器。您可以注意到,当用户抬起手指时,识别器的状态更改为UIGestureRecognizerStateEnded 。因此,除了导航控制器委托之外,您还应该将目标添加到流行识别器:
UIGestureRecognizer *popRecognizer = self.navigationController.interactivePopGestureRecognizer;
[popRecognizer addTarget:self
action:@selector(navigationControllerPopGestureRecognizerAction:)];
Run Code Online (Sandbox Code Playgroud)
每次 Pop 识别器更改时(包括手势结束)都会调用此操作。
- (void)navigationControllerPopGestureRecognizerAction:(UIGestureRecognizer *)sender
{
switch (sender.state)
{
case UIGestureRecognizerStateEnded:
// Next cases are added for relaibility
case UIGestureRecognizerStateCancelled:
case UIGestureRecognizerStateFailed:
_isAnimating = NO;
break;
default:
break;
}
}
Run Code Online (Sandbox Code Playgroud)
PS 不要忘记该interactivePopGestureRecognizer属性自 iOS 7 起就可用!
| 归档时间: |
|
| 查看次数: |
668 次 |
| 最近记录: |