0

奇妙なバグがあります。アプリが読み込まれ、ボタンをタップしてアニメーションを実行すると、アニメーションにコミットされませんが、2 回目に試すと完全に機能します。私のコードは次のとおりです。

-(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]];は、アニメーションの前後にラベルを変更するのが好きではないようです。完了機能を試してみましたが、ラベルを変更した後、アニメーション化され、すぐに古い位置にリセットされます。

setnamelabel メソッドを設定するためのボットによるリクエスト:

- (void) setNameLabel:(NSString *)sender Child:(NSNumber *)Child
{
    self.childnamelabel.text = sender;
    IsAChild = Child;
}

まだ未回答:(

4

1 に答える 1

0

あなたのコードは問題ないように見えますが、しばらく前に同様の問題がありました。ブロックの使用に切り替えたところ、うまくいきました。

使ってみて

-(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;
    }];
}
于 2013-02-13T19:30:29.757 に答える