我将名为 testLabel 的 UILabel 拖到 Storyboard 中的位置 A(140,40)。我想将它从 A 动画化到位置 B(100,250)。所以我写了如下代码..
#import "testViewController.h"
@interface testViewController ()
@property (weak, nonatomic) IBOutlet UILabel *testLabel;
@end
@implementation testViewController
- (void)viewDidLoad
{
[super viewDidLoad];
[UIView animateWithDuration:1.0
delay:1.0
options:UIViewAnimationOptionCurveLinear
animations:^{
CGPoint b = CGPointMake(100, 250);
self.testLabel.center = b;
}
completion:nil];
}
@end
模拟器不是从 A 到 B 设置动画,而是从点 (0,0) 到 A 设置标签动画。我哪里错了?
最佳答案
我不会在 viewDidLoad 方法中执行您的动画。此时,iOS 还没有完全计算出您的 subview 的框架。
如果您使用诸如 viewDidAppear 之类的方法制作此动画:那么您会发生什么?
关于iOS - 在 Storyboard 中创建的 UILabel 无法正确设置动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064806/