漂亮的下落式動畫載入視圖

來源:互聯網
上載者:User

標籤: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];

    }];

}

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.