gpt4 book ai didi

objective-c - 简单的 UIView 动画移动不起作用

转载 作者:行者123 更新时间:2023-11-28 22:47:55 26 4
gpt4 key购买 nike

我不知道为什么它不起作用。

我只想在 viewDidLoad 中做一个简单的 UIView 动画。

这是我的代码:

[UIView animateWithDuration:3.0f animations:^{
[self.headline setCenter:CGPointMake(0.0, 200.0)];
}];

没有任何反应。当我像这样测试在特定对象上调用动画方法的一般方法时:

[UIView animateWithDuration:3.0f animations:^{
[self.headline setAlpha:0.0];
}];

有效!!!为什么我不能在屏幕上移动 View ?我正在使用最新的 Xcode 4.5。

感谢您的任何建议!

更新:

当我在代码中手动添加 View 时,它起作用了。但是对于我在 Interface Builder 中创建为 Outlet 的 UIView,它不起作用。

UILabel *testLabel = [[UILabel alloc] initWithFrame:CGRectMake(0.0, 0.0, 200.0, 100.0)];
testLabel.backgroundColor = [UIColor redColor];

[self.view addSubview:testLabel];

[UIView animateWithDuration:3.0 animations:^{
testLabel.center = CGPointMake(0.0, 200);
}];

很明显我在 .xib 文件中做错了

最佳答案

不要在 viewDidLoad 中这样做。那个时候还没有这个观点。在 viewDidAppear 中尝试。

关于objective-c - 简单的 UIView 动画移动不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12725118/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com