zoukankan      html  css  js  c++  java
  • NSLayoutConstraints加动画来改变约束

    //
    //  ViewController.m
    //  NSLayoutAnimationDemo
    //
    //  Created by ebaotong on 15/7/22.
    //  Copyright (c) 2015年 com.csst. All rights reserved.
    //
    
    #import "ViewController.h"
    #define kWeakSelf(weakSelf) __weak typeof(self)weakSelf = self
    #define WS(weakSelf)  __weak __typeof(&*self)weakSelf = self
    @interface ViewController ()
    @property (weak, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;
    @property (weak, nonatomic) IBOutlet UIView *topView;
    
    
    @end
    
    @implementation ViewController
    
    - (void)viewDidLoad
    {
        [super viewDidLoad];
       
    }
    
    - (void)didReceiveMemoryWarning {
        [super didReceiveMemoryWarning];
        // Dispose of any resources that can be recreated.
    }
    /**需要对顶部约束拖线条来实现改变view的顶部约束*/
    - (IBAction)btnClick:(UIButton *)sender
    {
        
       kWeakSelf(weakSelf);
      [UIView animateWithDuration:0.8 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
          
          weakSelf.topConstraint.constant = [UIScreen mainScreen].bounds.size.height;
          /**必须要添加不然看起来无明显效果*/
          [weakSelf.view layoutIfNeeded];
      } completion:^(BOOL finished) {
          
          weakSelf.topConstraint.constant = 0.f;
          /**必须要添加不然看起来无明显效果*/
          [weakSelf.view layoutIfNeeded];
      }];
        
        
        
        
    }
    /**不需要对顶部约束拖线条来实现改变view的顶部约束*/
    - (IBAction)btnAction:(UIButton *)sender {
         kWeakSelf(weakSelf);
        [self.view.constraints enumerateObjectsUsingBlock:^(NSLayoutConstraint *constraint, NSUInteger idx, BOOL *stop)
         {
                if ((constraint.firstItem ==weakSelf.topView)&&(constraint.firstAttribute == NSLayoutAttributeTop))
            {
                [UIView animateWithDuration:1 delay:0 options:UIViewAnimationOptionCurveEaseInOut animations:^{
                    
                    constraint.constant = [UIScreen mainScreen].bounds.size.height;
                    /**必须要添加不然看起来无明显效果*/
                    [ weakSelf.view layoutIfNeeded];
                    
                } completion:^(BOOL finished) {
                    
                    constraint.constant = 0;
                    /**必须要添加不然看起来无明显效果*/
                    [ weakSelf.view layoutIfNeeded];
                }];
                
            }
            
        }];
    
    }
    
    @end

  • 相关阅读:
    特NB的本地语音识别方案(转)
    海思MPP(转)
    单片机实现PT2262解码示例代码(转)
    海思HI35XX之----视频处理单元各通道间的关系(转)
    海思AI芯片(Hi3519A/3559A)方案学习(三)Ubuntu18.0.4上编译Hi3519AV100 uboot和kernel(转)
    Hi3519V101开发环境搭建(二)(转)
    Git 原理
    海思3531添加移远EC20 4g模块(转)
    将移远通信的EC20驱动移植到NUC972上(转)
    Shell 正则表达式
  • 原文地址:https://www.cnblogs.com/thbbsky/p/4667403.html
Copyright © 2011-2022 走看看