私は3つのステップで2つのUIView(UIImageViewとUILabel)を一緒にアニメーション化しようとしています:
0)両方のビューが画面の左上隅にあります
1)次にフレームを変更します(ラベルのフォントサイズも)ビューが大きくなり、中央に 2)フレームを再度変更して(ラベルのフォントサイズも)、両方のビューを右下隅に配置します。(このアニメーションは数秒後に開始されます)
3) スーパービューから両方のビューを削除します。
UIImageView は、すべてのアニメーションの後で完璧です。UILabel の場合、最初のアニメーションは動作しますが、2 番目のアニメーションは動作しません! 最初のアニメーションの後、私のラベルはすぐに小さくなり、遅延の後、画像ビューのように動きます。どうしてか分かりません!「setFrame」を使用して、原点とサイズを一緒に変更します..
私のコードは次のとおりです。
@implementation Animazione
{
UIImageView * imageView;
UILabel * message;
}
-(void) startAnimationOn: (UIView *) superView;
{
UIImage * image = [UIImage imageNamed:@"..."];
imageView = [[UIImageView alloc] initWithFrame:CGRectMake(0,0,100,100)];
[imageView setImage:image];
[superView imageView];
CGRect startRect = [self startDimension]; //make a CGRect
[imageView setFrame:startRect];
message = [[UILabel alloc] init];
message.text = @"A text";
message.textAlignment = NSTextAlignmentCenter;
message.adjustsFontSizeToFitWidth = YES;
[self setLabelSize: startRect];
[message setBackgroundColor:[UIColor greenColor]];
[superView addSubview:message];
[UIView animateWithDuration:2.0
delay:3.0
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction|UIViewAnimationOptionBeginFromCurrentState)
animations:^{
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(hideViews:finished:context:)];
CGRect big = [self bigDimension];
[imageViews setFrame:big];
// [self setLabelSize:big];
[message setFrame:big];
}
completion:^(BOOL finished){
NSLog(@"grande");
}];
}
-(void) hideViews:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[UIView animateWithDuration:3.0
delay:5.0
options:(UIViewAnimationCurveEaseInOut|UIViewAnimationOptionAllowUserInteraction)
animations:^{
[UIView setAnimationDelegate:self];
[UIView setAnimationDidStopSelector:@selector(deliteViews:finished:context:)];
CGRect finally = [self finallyDimension];
[imageView setFrame:finally];
// [self setLabelSize:finally];
[message setFrame:finally];
}
completion:^(BOOL finished){
NSLog(@"scomparso");
}];
}
}
-(void) deliteViews:(NSString *)animationID finished:(NSNumber *)finished context:(void *)context
{
[imageView removeFromSuperview];
[message removeFromSuperview];
imageView = nil;
message = nil;
}
}
- (void)setLabelSize: (CGRect) originalDim
{
[message setFrame: originalDim];
message.font = [message.font fontWithSize:originalDim.size.height/8+10];
}
編集:
実際、私はアニメーションに何を期待し、代わりに何をするのかを十分に説明していません。最初のアニメーションについては、次のことを期待
してい
ます
。
最初のアニメーションでは、次のことが予想されます: -
5
秒間
何も起こらない (遅延)
-
画像
ビューとラベルが小さくなり、同時に移動する (持続時間 3 秒) imageview が小さくなって移動、ラベルが移動