• 漂亮的下落式动画载入视图


    - (IBAction)changePassWord:(id)sender

    {

        CGSize size = [[UIScreen mainScreen] bounds].size;

        

        //增加半透明层

        bgView = [[UIView alloc]initWithFrame:self.view.frame];

        bgView.backgroundColor = [UIColor colorWithWhite:0.2 alpha:0.7];

        [self.parentViewController.view addSubview:bgView];

        

        //把修改密码窗口加到父视图上,因为UITableView没法直接加subview。给窗口一个初始化的旋转角度。

        self.changePWD = [[self storyboard]instantiateViewControllerWithIdentifier:@"ChangePassWordID"];

        self.changePWD.delegate = self;

        [self.changePWD.view setFrame:CGRectMake(0, -200, 280, 200)];

        [self.changePWD.view setTransform:CGAffineTransformMakeRotation(-M_PI / 20)];

        [self.parentViewController.view addSubview:self.changePWD.view];

        

        //动画载入密码窗口

        [UIView animateWithDuration:0.3 animations:^{

            [self.changePWD.view setTransform:CGAffineTransformMakeRotation(0)];

            [self.changePWD.view setFrame:CGRectMake(20, size.height/2-100, 280, 200)];

        }];

        

        //给窗口增加拖动手势

        UIPanGestureRecognizer *panRecognizer = [[UIPanGestureRecognizer alloc] initWithTarget:self action:@selector(panPaswordView:)];

        [panRecognizer setMinimumNumberOfTouches:1];

        [panRecognizer setMaximumNumberOfTouches:1];

        [self.parentViewController.view addGestureRecognizer:panRecognizer];

        

    }

    -(void)panPaswordView:(id)sender {

        [self.view bringSubviewToFront:[(UIPanGestureRecognizer*)sender view]];

        CGPoint translatedPoint = [(UIPanGestureRecognizer*)sender translationInView:self.view];

        

        //拖动开始时记录浮动窗口的中心点

        if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateBegan) {

            firstX = self.changePWD.view.center.x;

            firstY = self.changePWD.view.center.y;

        }

        

        //获取拖动后的坐标

        translatedPoint = CGPointMake(firstX, firstY+translatedPoint.y);

        

        //禁止往上拖动

        if (translatedPoint.y < firstY) {

            return;

        }

        

        //在拖动时即时更新窗口位置

        [self.changePWD.view setCenter:translatedPoint];

        

        //拖动结束时关闭密码窗口,并移除附加的手势

        if ([(UIPanGestureRecognizer*)sender state] == UIGestureRecognizerStateEnded) {

            

            [self removePasswordView];

            

            [self.parentViewController.view removeGestureRecognizer:(UIPanGestureRecognizer*)sender];

        }

    }

    - (void)removePasswordView

    {

        [UIView animateWithDuration:0.5 animations:^{

            

            [self.changePWD.view setFrame:CGRectMake(20, 1136, 280, 200)];

            bgView.alpha = 0.0;

            

        } completion:^(BOOL finished) {

            [self.changePWD.view removeFromSuperview];

            [bgView removeFromSuperview];

        }];

    }

  • 相关阅读:
    Magento入门开发教程
    Magento文件系统目录结构
    正则匹配获取HTML图片地址,正则匹配获取HTML内容
    php+phpspreadsheet读取Excel数据存入mysql
    PHP遍历一个文件夹下所有文件和子文件夹的函数
    前端实现在线预览pdf、word、xls、ppt等文件
    微服务架构的基础框架选择
    Linux性能优化实战学习笔记:第五十八讲
    Linux性能优化实战学习笔记:第五十六讲
    Linux性能优化实战学习笔记:第五十五讲
  • 原文地址:https://www.cnblogs.com/tuhaoYY/p/3854005.html
Copyright © 2020-2023  润新知