UILabel
を使用してのみ幅が増減するように、の幅をアニメーション化するにはどうすればよいですか。UIView
animateWithDuration
あなたの助けに感謝します(この時点で私はそうしようとしていたのでとてもイライラしていますが、それはうまくいきません)
UILabel
を使用してのみ幅が増減するように、の幅をアニメーション化するにはどうすればよいですか。UIView
animateWithDuration
あなたの助けに感謝します(この時点で私はそうしようとしていたのでとてもイライラしていますが、それはうまくいきません)
UILabel
UIViewアニメーションブロック内のフレームを設定できます。このようなもの:
CGRect originalFrame = self.address.frame;
[UIView animateWithDuration:0.3
animations:^{
self.myLabel.frame = CGRectMake(0, 0, 100, 100);
}
completion:^(BOOL finished) {
// use similar UIView animation to resize back to original
}];
明らかに、フィードするサイズはアプリによって異なり、コンテンツに基づいて計算される場合があります。
以下のようなアニメーションでフレーム幅を増減してみてください
// original label frame CGRectMake( 0,0, 100,60 );
[UIView beginAnimations: @"moveLogo" context: nil];
[UIView setAnimationDelegate:self];
[UIView setAnimationDuration:1.0];
[UIView setAnimationCurve: UIViewAnimationCurveLinear];
[UIView setAnimationRepeatAutoreverses:YES];
[UIView setAnimationRepeatCount:4];
//increasing frame width
label.frame = CGRectMake( 0,0, 400,60 );
[UIView commitAnimations];
これを試して
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(100, 100, 200, 100);
}completion:^(BOOL finished) {
[UIView animateWithDuration:0.6 animations:^(void)
{
self.label.bounds = CGRectMake(100, 100, 100, 100);
}];
}];
ついにiOS5.0のブロックでこのようになりました
[UIView animateWithDuration:2. delay:0 options:UIViewAnimationOptionAutoreverse|UIViewAnimationOptionBeginFromCurrentState animations:^{
[self.messageLabel setFrame:CGRectMake(90, 0, labelSize.width, 90)];
} completion:^(BOOL finished) {
}];
私はこのようにそれを行うことができました。自己とは、ラベルを追加するビューを指します。initで、幅が1ピクセルのラベルを追加します。次に、以下を使用します。UIViewAnimationOptionBeginFromCurrentStateを使用すると、ドアのように開くことができます。
[UIView animateWithDuration:1. delay:0 options:UIViewAnimationOptionBeginFromCurrentState animations:^{
[self setFrame:CGRectMake(self.frame.origin.x-labelSize.width-PADDING, self.frame.origin.y, self.frame.size.width+labelSize.width+PADDING, self.frame.size.height)];
[self.messageLabel setFrame:CGRectMake(95, 10, labelSize.width, labelSize.height)];
self.messageLabel.alpha = 1;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:2. options:0 animations:^{
self.messageLabel.alpha = 0;
} completion:^(BOOL finished) {
[UIView animateWithDuration:1. delay:0. options:0 animations:^{
[self setFrame:CGRectMake(self.frame.origin.x+labelSize.width+PADDING, self.frame.origin.y, self.frame.size.width-labelSize.width-PADDING, self.frame.size.height)];
} completion:^(BOOL finished) {
}];
}];
}];