UIView transitionWithView&设置框架不再适用于iOS8 [英] UIView transitionWithView & setting the frame no longer works iOS8

查看:654
本文介绍了UIView transitionWithView&设置框架不再适用于iOS8的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

自更新到iOS8以来,许多动画都停止了工作。看来无法更改视图的 y 位置。在iOS7中没有问题。但是对于iOS8,它不会超过原来的 y 位置。看起来视图的帧确实正在更新,但帧没有被重绘。这是我的代码

Since updating to iOS8 many animations have stopped working. It appears that the y position of the view cannot be changed. In iOS7 there was no problem. But with iOS8 it will not go past the original y position.It appears that the frame of the view are indeed being updated but the frame is not being redrawn. Here is my code

[UIView transitionWithView:self.view duration:0.3 options:UIViewAnimationOptionCurveEaseInOut animations:^{

self.table.frame = CGRectMake(0, (self.view.bounds.size.height - self.button.frame.size.height) - (252), self.view.bounds.size.width, self.table.frame.size.height);


} completion:nil];

我也在动画块之外尝试过这段代码;

I have also tried this code outside of the animation block;

  self.table.frame = CGRectMake(0, (self.view.bounds.size.height - self.button.frame.size.height) - (252), self.view.bounds.size.width, self.table.frame.size.height);


推荐答案

更新解决方案是调整自动布局约束而不是框架来源。单击要调整的自动布局约束(在界面构建器中,例如顶部约束)。接下来将其设为 IBOutlet ;

Update The solution is to adjust the auto layout constraints and not the frames origin. Click on the auto layout constraint you would like to adjust (in interface builder e.g top constraint). Next make this an IBOutlet;

@property (strong, nonatomic) IBOutlet NSLayoutConstraint *topConstraint;

然后给它制作动画;

 self.topConstraint.constant = -100;
[self.viewToAnimate setNeedsUpdateConstraints];  
    [UIView animateWithDuration:.3 animations:^{
        [self.viewToAnimate layoutIfNeeded]; 
    }];

上述代码将移动视图/或向上移动约束。要将其向下移动到原来的简单调用;

The above code will move the view/ or move the constraints upwards. To move it backdown to its original simply call;

  self.topConstraint.constant = 0;
[self.viewToAnimate setNeedsUpdateConstraints];
    [UIView animateWithDuration:.3 animations:^{
        [self.viewToAnimate layoutIfNeeded]; 
    }];

第二个解决方案
我找到了解决方案。看来,如果 self.table 是一个 IBOutlet ,那么动画将不起作用。我猜这是新动态故事板的结果。在代码中而不是在故事板中创建所有元素会导致动画成功。这就是我必须要做的就是在代码中创建 UITableView

Second Solution I found the solution. It appears that if self.table is an IBOutlet then the animation wont work. I am guessing this a result of the new dynamic storyboards. Creating your elements all in code and not in the storyboard leads to a successful animation. That is all I had to do to get it to work, create the UITableView in code.

这篇关于UIView transitionWithView&设置框架不再适用于iOS8的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆