动画不会第一次运行
我有一个奇怪的错误。当我的应用程序加载时,我点击一个按钮来做一个动画,它不承诺动画,但当我第二次尝试完美的作品。继承人我的代码:动画不会第一次运行
-(void)Revert
{
firstTable.hidden = FALSE;
self.navigationItem.leftBarButtonItem = NO;
[self returnanimation];
}
-(void)returnanimation
{
CGRect labelframe = childnamelabel.frame;
labelframe.origin.x = 493.5; // new x coordinate
labelframe.origin.y = 359; // new y coordinate
CGRect textframe = passwordfield.frame;
textframe.origin.x = 454; // new x coordinate
textframe.origin.y = 388; // new y coordinate
CGRect submitframe = submit.frame;
submitframe.origin.x = 640; // new x coordinate
submitframe.origin.y = 387; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.25];
childnamelabel.frame = labelframe;
passwordfield.frame = textframe;
submit.frame = submitframe;
[UIView commitAnimations];
}
-(void)animation
{
CGRect labelframe = childnamelabel.frame;
labelframe.origin.x = 335.5; // new x coordinate
labelframe.origin.y = 359; // new y coordinate
CGRect textframe = passwordfield.frame;
textframe.origin.x = 294; // new x coordinate
textframe.origin.y = 388; // new y coordinate
CGRect submitframe = submit.frame;
submitframe.origin.x = 480; // new x coordinate
submitframe.origin.y = 387; // new y coordinate
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration: 0.25];
childnamelabel.frame = labelframe;
passwordfield.frame = textframe;
submit.frame = submitframe;
[UIView commitAnimations];
}
-(IBAction)PressedTeacherButton: (UIBarButtonItem*) Teacherbutton
{
[self setNameLabel: @"Mrs Hayward" Child:[NSNumber numberWithInt:0]];
firstTable.hidden = TRUE;
self.navigationItem.leftBarButtonItem = [[UIBarButtonItem alloc] initWithBarButtonSystemItem:UIBarButtonSystemItemCancel target:self action:@selector(Revert)];
[self animation];
//Pass on admins name and also bool whether they are a child.
}
试图寻找解决方案,但找不到任何东西。感谢您的帮助:d
* UPDATE
范围缩小到[self setNameLabel: @"Mrs Hayward" Child:[NSNumber numberWithInt:0]];
似乎动画不喜欢动画之前也没有改变后的标签。我已经尝试完成功能,它动画,然后立即重置到旧位置后更改标签。
请求由BOT忍受setnamelabel方法:
- (void) setNameLabel:(NSString *)sender Child:(NSNumber *)Child
{
self.childnamelabel.text = sender;
IsAChild = Child;
}
仍然无人应答:(
虽然你的代码看起来不错,我也有类似的问题,一段时间后,我切换到使用块,它。工作
尝试使用
-(void)animation
{
CGRect labelframe = childnamelabel.frame;
labelframe.origin.x = 335.5; // new x coordinate
labelframe.origin.y = 359; // new y coordinate
CGRect textframe = passwordfield.frame;
textframe.origin.x = 294; // new x coordinate
textframe.origin.y = 388; // new y coordinate
CGRect submitframe = submit.frame;
submitframe.origin.x = 480; // new x coordinate
submitframe.origin.y = 387; // new y coordinate
[UIView animateWithDuration:0.25 animations:^{
childnamelabel.frame = labelframe;
passwordfield.frame = textframe;
submit.frame = submitframe;
}];
}
感谢您的帮助。不幸的是,它没有任何不同,试图从一开始就预装动画,但仍然没有任何东西!没有任何意义:( – user1816481 2013-02-13 19:55:37
好吧,我评论了[self setNameLabel:@“Mrs Hayward”Child:[NSNumber numberWithInt:0]];这一次它工作,奇怪的错误,但我会尝试解决它: ) – user1816481 2013-02-13 19:57:48
为了方便其他观众。我在之前的评论中评论过的方法是改变一个将被动画化的标签,它似乎不喜欢在动画之前更改值。一个奇怪的错误:P,必须做动画 – user1816481 2013-02-13 20:05:29
发表您的'sentNameLabel:儿童:'方法代码 – ColdLogic 2013-02-13 20:49:16
您使用的是哪个iOS版本? – Bot 2013-02-14 18:21:47
我正在使用iOS版本6.1 – user1816481 2013-02-14 19:56:23