zoukankan      html  css  js  c++  java
  • 上拉、下拉UITableView,交互式 模态弹出(自定义弹出动画)

    部分代码 InteractiveTransition 类继承NSObject:

    - (instancetype)initWithPresentingController:(UITableViewController *)presentingVc presentedController:(UIViewController *)presentedVc {
        self = [super init];
        if (self) {
            self.vc = presentedVc;
            self.vc.transitioningDelegate =self;
            self.presentingVc = presentingVc;
        }
        return self;
    }
    
    - (void)new_scrollViewWillBeginDragging:(UIScrollView *)scrollView {
        self.interactiveTransition = [[UIPercentDrivenInteractiveTransition alloc]init];
        [self.presentingVc presentViewController:self.vc animated:YES completion:nil];
    }
    
    - (void)new_scrollViewDidScroll:(UIScrollView *)scrollView {
        
        CGFloat offsetY = fabs(scrollView.contentOffset.y);
        
        CGFloat screenH = [UIScreen mainScreen].bounds.size.height / 3.0;
        progress = offsetY / screenH;
        progress = progress-0.3;
        if (progress > 0) {
            [self.interactiveTransition updateInteractiveTransition:progress];
        }
        
    }
    - (void)new_scrollViewWillEndDragging {
        if (progress < 0.4) {
            [self.interactiveTransition cancelInteractiveTransition];
        }else {
            [self.interactiveTransition finishInteractiveTransition];
        }
        self.interactiveTransition = nil;
    }
    
    - (nullable id <UIViewControllerAnimatedTransitioning>)animationControllerForPresentedController:(UIViewController *)presented presentingController:(UIViewController *)presenting sourceController:(UIViewController *)source {
        
        return self.animation;
    }
    
    - (id<UIViewControllerInteractiveTransitioning>)interactionControllerForPresentation:(id<UIViewControllerAnimatedTransitioning>)animator {
        
        return self.interactiveTransition;
    }

    PresentAnimation 类继承NSObject 实现 UIViewControllerAnimatedTransitioning协议

    - (NSTimeInterval)transitionDuration:(id<UIViewControllerContextTransitioning>)transitionContext {
        return 1.0;
    }
    
    - (void)animateTransition:(id<UIViewControllerContextTransitioning>)transitionContext {
        
        UIView *toView = [transitionContext viewForKey:UITransitionContextToViewKey];
        UIView *containerView = [transitionContext containerView];
        [containerView addSubview:toView];
        
        toView.frame = CGRectMake(50, containerView.bounds.size.height, containerView.bounds.size.width - 100, containerView.bounds.size.height - 300);
        
        [UIView animateWithDuration:[self transitionDuration:transitionContext] animations:^{
            toView.frame = containerView.bounds;
        }completion:^(BOOL finished) {
            [transitionContext completeTransition:![transitionContext transitionWasCancelled]];
        }];
        
    }

    控制器:

    - (InteractiveTransition *)interactive {
        if (!_interactive) {
            _interactive = [[InteractiveTransition alloc]initWithPresentingController:self presentedController:[[TwoViewController alloc]init]];
        }
        return _interactive;
    }
    - (void)scrollViewWillBeginDragging:(UIScrollView *)scrollView {
        
        [self.interactive new_scrollViewWillBeginDragging:scrollView];
    }
    
    
    - (void)scrollViewWillEndDragging:(UIScrollView *)scrollView withVelocity:(CGPoint)velocity targetContentOffset:(inout CGPoint *)targetContentOffset {
        
        [self.interactive new_scrollViewWillEndDragging];
    }
    - (void)scrollViewDidScroll:(UIScrollView *)scrollView {
        
        [self.interactive new_scrollViewDidScroll:scrollView];
    }

    完整代码:http://pan.baidu.com/s/1i3Uewip

  • 相关阅读:
    RHEL 6.3安装(超级详细图解教程)[转载]
    CentOS下设置vimrc,添加文件注释信息以及设置tab 键为4 格
    Centos 设置时区和时间以及增加中文输入法
    虚拟机上CentOS6.5 无法上网的解决方法
    LoadRunner 11安装及测试环境搭建
    LR11录制回放出现中文乱码以及录制时一直跳到360浏览器的解决方法
    第 3 章 变量和表达式
    第 2 章 编写 C# 程序
    第 1 章 C# 简介
    jQuery Mobile的学习时间bottonbutton的事件学习
  • 原文地址:https://www.cnblogs.com/CyanStone/p/5116946.html
Copyright © 2011-2022 走看看