我有一个奇怪的错误。当我的应用程序加载并且我点击一个按钮来制作动画时,它不会提交动画,但是当我第二次尝试时它可以完美运行。这是我的代码:
-(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
*更新
将其缩小到[self setNameLabel: @"Mrs Hayward" Child:[NSNumber numberWithInt:0]];
似乎动画不喜欢在动画之前或之后更改标签。我已经尝试了完成功能,它会动画然后在更改标签后立即重置到旧位置。
请求 BOT 提出 setnamelabel 方法:
- (void) setNameLabel:(NSString *)sender Child:(NSNumber *)Child
{
self.childnamelabel.text = sender;
IsAChild = Child;
}
仍然没有答案:(