iOS - 在 Storyboard 中创建的 UILabel 无法正确设置动画

标签 ios animation storyboard

我将名为 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/

相关文章:

ios - CGAffineTransformMakeScale 动画不工作

ios - 使用 UIViewController 动画显示 UINavigationController

ios - 使用 swift 4 使用 Multipart 和 Alamofire 将图像上传到服务器

c++ - iOS 构建中的非法操作码

jquery - 使用 jQuery 触发多个动画 onScroll 事件

ios - UITabBarController 委托(delegate)与 Storyboard

iphone - 为 iPhone 和 iPad 使用不同的 Storyboard时如何为按钮设置 Action ?

ios - IOS设备上Unity WEBGL中的音频

ios - 无法在 Xcode 中创建分发应用程序

java - 将 Sprite 表动态切割成具有可变帧大小的单独位图