0

「nameLabel」というUILabelがあり、アニメーションブロック内にあるため、これが発生します。

_nameLabel.alpha = 1;
CGAffineTransform translate = CGAffineTransformMakeTranslation(50, 50);
_nameLabel.transform = translate;

UILabel を指定した場所にアニメーション化すると思いましたが、上記の場所から Interface Builder にある場所にアニメーション化するだけです。ここで何か助けはありますか?

4

2 に答える 2

1

アニメーション ブロックとその他の関連コードを投稿できますか? ラベルがどうなるかはわかりませんCGAffineTransformMakeTranslationが、フレームの位置をアニメーション化する場合は、これを使用できます。

CGRect frame = _nameLabel.frame;
frame.origin.y = 100; //Desired height, origin.x can be modified as well. 
//You can also change the frame size here but it wont work on UILabels, you will need `CGAffineTransformScale` for that.

[UIView animateWithDuration: 1.5
                      delay:0.0
                    options:UIViewAnimationCurveEaseInOut | UIViewAnimationOptionBeginFromCurrentState
                 animations:^ {

                     [_nameLabel setFrame:frame];

                 }
                 completion:^ (BOOL finished) {

                 }];

編集:他の方法:

CGRect frame = _nameLabel.frame;
frame.origin.y = 100;

[UIView beginAnimations:nil context:nil];
[UIView setAnimationBeginsFromCurrentState:YES];
[UIView setAnimationDuration:0.5];

[_nameLabel setFrame: newFrame];

[UIView commitAnimations];

現在の状態はおそらくラベルの現在の場所です。最初にそれを試してみますが、何も起こらない場合はUIViewAnimationOptionBeginFromCurrentState、アニメーションの前にラベルのフレームを削除または別の場所に設定し、最初の位置 (xib ファイル内の位置) に移動します。アニメーション ブロック、それはあなたの呼び出しです。

于 2012-11-16T08:31:31.360 に答える
1

Autolayout は多くの問題を引き起こすため、注意してください。

「自動レイアウトを使用」の選択を解除してみてください

オブジェクトを翻訳しようとするすべての問題を解決してくれます。

于 2012-12-12T17:21:47.707 に答える