zoukankan      html  css  js  c++  java
  • 使用autoLayout布局view,在代码中修改frame解决方案

    在xib或者storyBoard中给aView使用autoLayout设定了约束,但是想让aView做一个简单的动画,比如从约束的A位置(0,0,100,100)移动到B位置(0,66,100,100)的简单动画。

    那么你会发现,如果在xib或者storyBoard中设定了约束,在代码中直接修改aView的frame行不通的。

    实现结果就是在ios7上没问题,但是在ios8上发现aView从A移动到B,但是又返回A(具体差别还没找到)

    解决方案:

    loginViewTopConstraint = [NSLayoutConstraint constraintWithItem:self.loginView attribute:NSLayoutAttributeTop relatedBy:NSLayoutRelationEqual toItem:self.view attribute:NSLayoutAttributeTop multiplier:1.0 constant:66];//定义新约束

        [self.view removeConstraint:self.topConstraint];//移除旧约束

        [self.view addConstraint:loginViewTopConstraint];//添加新约束

        [self.view layoutIfNeeded];//使约束生效

  • 相关阅读:
    hdu 2680:Choose the best route(Dijkstra , SPFA)
    Gym
    Gym
    Gym
    常用的相似度计算
    kafka 配置
    Kafka-broker配置说明
    kafka 安装以及测试
    adaboost算法
    solr scheme配置简介
  • 原文地址:https://www.cnblogs.com/guatiantian/p/4228876.html
Copyright © 2011-2022 走看看