大佬教程收集整理的这篇文章主要介绍了iOS – 在关闭和滚动手势之间切换,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
@interface NavigationController : UINavigationController <UIViewControllerTransitioningDelegate> @property (nonatomic,strong) UIPanGestureRecognizer *gestureRecog; - (void)handleGesture:(UIPanGestureRecognizer*)gestureRecognizer; @end@H_616_5@NavigationController.m @H_616_5@
#import "NavigationController.h" #import "AnimationController.h" #import "TransitionController.h" @implementation NavigationController { AnimationController *_animator; TransitionController *_interactor; } - (instanCETypE)init { self = [super init]; self.transitioningDelegate = self; _animator = [[AnimationController alloc] init]; _interactor = [[TransitionController alloc] init]; return self; } - (void)viewDidLoad { [super viewDidLoad]; // Set the gesture recognizer self.gestureRecog = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@SELEctor(handleGesture:)]; [self.view addGestureRecognizer:_gestureRecog]; } - (id<UIViewControllerInteractiveTransitioning>)interactionControllerForDismissal:(id<UIViewControllerAnimatedTransitioning>)animator { if (animator == _animator && _interactor.hasStarted) { return _interactor; } return nil; } - (id<UIViewControllerAnimatedTransitioning>)animationControllerForDismissedController:(UIViewController *)dismissed { if (dismissed == self || [self.viewControllers indexOfObject:dismissed] != NsnotFound) { return _animator; } return nil; } - (void)handleGesture:(UIPanGestureRecognizer *)gestureRecog { CGFloat threshold = 0.3f; CGPoint translation = [gestureRecog translationInView:self.view]; CGFloat verticalMovement = translation.y / self.view.bounds.size.height; CGFloat downWARDR_127_11845@ovement = fmaxf(verticalMovement,0.0f); CGFloat downWARDR_127_11845@ovementPercent = fminf(downWARDR_127_11845@ovement,1.0f); switch (gestureRecog.statE) { case UIGestureRecognizerStateBegan: { _interactor.hasStarted = YES; [self dismissviewControllerAnimated:YES completion:nil]; break; } case UIGestureRecognizerStateChanged: { if (!_interactor.hasStarted) { _interactor.hasStarted = YES; [self dismissviewControllerAnimated:YES completion:nil]; } _interactor.shouldFinish = downWARDR_127_11845@ovementPercent > threshold; [_interactor updateInteractiveTransition:downWARDR_127_11845@ovementPercent]; break; } case UIGestureRecognizerStateCancelled: { _interactor.hasStarted = NO; [_interactor cancelInteractiveTransition]; break; } case UIGestureRecognizerStateEnded: { _interactor.hasStarted = NO; if (_interactor.shouldFinish) { [_interactor finishInteractiveTransition]; } else { [_interactor cancelInteractiveTransition]; } break; } default: { break; } } } @end@H_616_5@现在,我必须在滚动视图到达顶部时触发手势处理.所以,这就是我在视图控制器中所做的. @H_616_5@WebViewController.m @H_616_5@
#import "WebViewController.h" #import "NavigationController.h" @interface WebViewController () @property (weak,nonatomiC) IBOutlet UIWebView *webView; @end @implementation WebViewController { BOOL _isHandlingPan; CGPoint _topContentOffset; } - (void)viewDidLoad { [super viewDidLoad]; [self.webView.scrollView setDelegate:self]; } - (void)scrollViewDidScroll:(UIScrollView *)scrollView { if ((scrollView.panGestureRecognizer.state == UIGestureRecognizerStateBegan || scrollView.panGestureRecognizer.state == UIGestureRecognizerStateChanged) && ! _isHandlingPan && scrollView.contentOffset.y < self.navigationController.navigationBar.translucent ? -64.0f : 0) { NSLog(@"Adding scroll target"); _topContentOffset = CGPointMake(scrollView.contentOffset.x,self.navigationController.navigationBar.translucent ? -64.0f : 0); _isHandlingPan = YES; [scrollView.panGestureRecognizer addTarget:self action:@SELEctor(handleGesture:)]; } } - (void)scrollViewDidEndDragging:(UIScrollView *)scrollView willDecelerate:(BOOL)decelerate { NSLog(@"Did End Dragging"); if (_isHandlingPan) { NSLog(@"Removing action"); _isHandlingPan = NO; [scrollView.panGestureRecognizer removeTarget:self action:@SELEctor(handleGesture:)]; } } - (void)handleGesture:(UIPanGestureRecognizer*)gestureRecognizer { [(NavigationController*)self.navigationController handleGesture:gestureRecognizer]; }@H_616_5@这仍然无法正常工作.即使在解雇动画期间,滚动视图仍然会以手势滚动. @H_616_5@结束EDIT1
id<UIViewControllerTransitioningDelegate> transitioningDelegate;@H_616_5@然后将这两种方法实现 @H_616_5@
//Asks your delegate for the transition animator object to use when dismissing a view controller. - animationControllerForDismissedController: //Asks your delegate for thE interactive animator object to use when dismissing a view controller. - interactionControllerForDismissal:@H_616_5@当拖动到顶部时,您开始转换,您可以使用UIPercentDrivenInteractiveTransition来控制滚动期间的进度. @H_616_5@您也可以参考ZFDragableModalTransition的源代码 @H_616_5@ZFDragableModalTransition的图片
以上是大佬教程为你收集整理的iOS – 在关闭和滚动手势之间切换全部内容,希望文章能够帮你解决iOS – 在关闭和滚动手势之间切换所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。