码迷,mamicode.com
首页 > 其他好文 > 详细

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

时间:2014-07-19 16:31:10      阅读:227      评论:0      收藏:0      [点我收藏+]

标签:color   io   for   cti   re   c   

- (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];

    }];

}

漂亮的下落式动画载入视图,布布扣,bubuko.com

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

标签:color   io   for   cti   re   c   

原文地址:http://www.cnblogs.com/tuhaoYY/p/3854005.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!