【问题标题】:Auto Layout UIView on constraint change does not animate iOS 7约束更改时的自动布局 UIView 不会为 iOS 7 设置动画
【发布时间】:2015-02-26 13:11:52
【问题描述】:

我正在尝试使用 AutoLayout 从“自下而上”为视图设置动画。

这在 iOS 8 中效果很好,但在 iOS 7 中却没有动画效果。

这是一个代码sn-p:

@interface ViewController ()
@property (strong) AViewController *aVC;
@end

@implementation ViewController

- (void)viewDidLoad
{
    [super viewDidLoad];
    self.aVC = [[AViewController alloc] init];
    self.aVC.view.translatesAutoresizingMaskIntoConstraints = NO;
    [self.view addSubview:self.aVC.view];
    [self.aVC.view autoPinEdgeToSuperviewEdge:ALEdgeLeft withInset:0];
    [self.aVC.view autoSetDimension:ALDimensionHeight    toSize:100];
    [self.aVC.view autoSetDimension:ALDimensionWidth     toSize:320];
     NSLayoutConstraint *constraint = [self.aVC.view autoPinEdgeToSuperviewEdge:ALEdgeBottom withInset:-100];
     [self.view layoutIfNeeded];
    [UIView animateWithDuration:2 animations:^{
        constraint.constant = -25;
        [self.view layoutIfNeeded];
    }];

}

我正在使用出色的 PureLayout 类别,以便轻松添加约束。

附加 project sample on Github - 适用于 iOS 8 模拟器,而不是 iOS 7 模拟器。

关于如何在 iOS 7 上进行这项工作的任何建议?

【问题讨论】:

    标签: ios iphone ios7 ios8 autolayout


    【解决方案1】:

    如果您将[self.view layoutIfNeeded] 替换为[self.aVC.view layoutIfNeeded],它将适用于两个iOS 版本。具体原因我不知道。

    编辑。

    请尝试类似的方法。

    [self.aVC.view layoutIfNeeded];
    [UIView animateWithDuration:2 animations:^{
        constraint.constant = -25;
        [self.view layoutIfNeeded];
    }];
    

    【讨论】:

    • 请看我更新的问题;它不适用于其中包含子视图的 xib。
    • 我下载了旧的,它对我有用。你在 xib 中修改了什么吗?
    • 是的,它确实在第一次提交时使用了一个空的 xib。我在 xib 中添加了一个标签和两个图像,现在它在 iOS 7 上没有动画效果。谢谢。
    猜你喜欢
    • 2014-01-27
    • 1970-01-01
    • 1970-01-01
    • 2019-06-05
    • 1970-01-01
    • 2014-05-26
    • 2012-10-29
    • 1970-01-01
    • 2012-11-24
    相关资源
    最近更新 更多