我正在尝试通过三个步骤将两个 UIView(一个 UIImageView 和一个 UILabel)一起制作动画:
0)两个视图都位于屏幕的左上角
1)然后我更改框架(以及标签字体大小)所以视图变得更大并且在中心 2)我再次更改框架(以及标签字体大小)以将两个视图放在右下角。(这个动画在几秒钟后开始)
3)我从超级视图中删除了两个视图。
UIImageView 在每个动画之后都是完美的。对于 UILabel,第一个动画作品,第二个没有!在第一次动画之后,我的标签立即变小,延迟后它像图像视图一样移动。我不知道为什么!我使用“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];
}
编辑:
实际上,我并没有很好地解释我对动画的期望以及它们的作用。对于第一个动画,我希望:
- 3 秒内什么都没有(延迟)
- imageview 和标签同时增长和移动(持续时间 2 秒)
它发生了。
对于第一个动画,我希望:
- 5 秒内什么都没有(延迟)
- imageview 和标签变小并同时移动(持续时间 3 秒)
真正发生了什么:
-标签立即改变尺寸
- 5 秒内没有
- imageview 变小并移动,标签移动