0

私はこの髪を引っ張る問題を抱えています。誰かが私を助けてくれることを願っています. ちょっとしたことのようですが、解決策を見つけることができませんでした。

アニメーション ブロックで移動したい UIButton があります。ボタンをクリックするたびに、新しい場所に移動します。ボタンは常に正しい場所に移動します。問題は、常に最初の場所から新しい場所に移動することです。

私がボタンを持っているとしましょう(0,0)(0,50)今、私はボタンをに移動したいのですが、それ(0,100)がアニメーション化(0,50)するの(0,100)は何ですか?(0,0)(0,100)

UIButtonアニメーション ブロックに新しいフレームを設定して移動します

[UIView animateWithDuration:0.5f
                              delay:0.0f
                            options:UIViewAnimationCurveLinear
                         animations:^{
                         }
                         completion:nil];

私の場合、他のコントロールの移動が完了したら、ボタンを完了ブロックに移動します。

誰かが私が話していることを正確に知っていて、私に答えてくれることを本当に願っています。

uibutton をアニメーション化するために使用するコードはこれです。ボタンの名前は「btnAddPhoneNumber」で、「送信者」でもあります。

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationCurveLinear
                 animations:^{
                     txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);

                 }
                 completion:^(BOOL finished) {
                     txtNewPhoneNumber.placeholder = @"here you go!";

                     //animate add textfield button.
                     [UIView animateWithDuration:0.5f
                                           delay:0
                                         options:UIViewAnimationCurveLinear
                                      animations:^{



                                          [sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];

                                          txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);

                                          [btnDelete setFrame:btnDeleteRect];
                                      }
                                      completion:^(BOOL finished) {
                                      }];
                 }];

私の質問を読んでいただき、解決策を見つけていただきありがとうございます。

EDIT(コード例を追加)

4

3 に答える 3

0

2 番目のアニメーションのオプションに追加UIViewAnimationOptionBeginFromCurrentStateしてみて、問題が解決するかどうかを確認してください。

[UIView animateWithDuration:0.5f
                              delay:0.0f
                            options:UIViewAnimationCurveLinear | UIViewAnimationOptionBeginFromCurrentState
                         animations:^{
                         }
                         completion:nil];

もう 1 つの方法は、2 番目のアニメーションの完了ハンドラーでボタンのフレームを (同じ値に) 再度設定することです。

于 2012-10-30T21:16:59.640 に答える
0

この回避策を確認してください。コメントで述べたように、これを最後のオプションとして使用できます。推奨されるアプローチではありません。

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationCurveLinear
                 animations:^{
                     txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);

                 }
                 completion:^(BOOL finished) {
                     txtNewPhoneNumber.placeholder = @"here you go!";

                     [self performSelector:@selector(callSecondAnimation) withObject:nil afterDelay:1.5f)]; //or 0.5f
                 }];

- (void)callSecondAnimation {
    //animate add textfield button.
    [UIView animateWithDuration:0.5f
                          delay:0
                        options:UIViewAnimationCurveLinear
                     animations:^{

                         [sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];

                         txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);

                         [btnDelete setFrame:btnDeleteRect];
                     }
                     completion:^(BOOL finished) {
                     }];
}

アップデート:

まずはこれを試して、

[UIView animateWithDuration:1
                      delay:0
                    options:UIViewAnimationCurveLinear
                 animations:^{
                     txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);

                 }
                 completion:^(BOOL finished) {
                     txtNewPhoneNumber.placeholder = @"here you go!";
                     txtNewPhoneNumber.frame = CGRectMake(newXnumber, newYnumber, txtPhoneNumber.frame.size.width, txtPhoneNumber.frame.size.height);//try setting it here once and then call next one
                     [self callSecondAnimation];
                 }];

- (void)callSecondAnimation {
    //animate add textfield button.
    [UIView animateWithDuration:0.5f
                          delay:0
                        options:UIViewAnimationCurveLinear
                     animations:^{

                         [sender setFrame:CGRectMake(btnAddPhoneNumber.frame.origin.x, newYnumber, btnAddPhoneNumber.frame.size.width, btnAddPhoneNumber.frame.size.height)];

                         txtNewPhoneNumberTitle.frame = CGRectMake(newXtitle, newYtitle, txtPhoneNumberTitle.frame.size.width, txtPhoneNumberTitle.frame.size.height);

                         [btnDelete setFrame:btnDeleteRect];
                     }
                     completion:^(BOOL finished) {
                     }];
}
于 2012-10-30T21:48:28.817 に答える
0

問題が見つかりました。ビューは AutoLayout を使用していました。AutoLayout の目盛りを削除すると、ボタンの新しい位置が保存され、次のアニメーションは以前の場所から続行されます。

ACB と Tobi の意見に感謝します。さまざまな解決策を試してみて、問題を解決することができました。

于 2012-11-01T12:58:47.543 に答える