繁体   English   中英

简单的UIView动画移动不起作用

[英]Simple UIView animation move doesn't work

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

我想要做的就是在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];
}];

有用!!! 为什么我无法在屏幕上移动视图? 我正在使用最新的Xcode 4.5。

谢谢你的建议!

更新:

当我在代码中手动添加视图时,它可以工作。 但对于UIViews,我在Interface Builder中创建Outlets它不起作用。

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中试一试。

好吧,我认为缺少动画的原因是我从视图控制器调用了一个不同的推送导航动画,它正在推动屏幕上的实际视图:

- (IBAction)goForSelection:(id)sender
{
    SelectionViewController *selectionViewController = [[SelectionViewController alloc] initWithNibName:@"SelectionViewController" bundle:nil];

    //[self.navigationController pushViewController:selectionViewController animated:YES];

    [UIView transitionWithView:self.navigationController.view duration:1.0 options:UIViewAnimationOptionTransitionFlipFromRight animations:^{
        [self.navigationController pushViewController:selectionViewController animated:NO];
    } completion:^(BOOL finished) {
        [selectionViewController startIntroAnimation];
    }];
}

首先,我检查了使用默认导航控制器segue时会发生什么。 令我惊讶的是动画确实开始了。 然后我将对[selectionViewController startIntroAnimation]的调用插入到完成块中,这也适用。

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM