Ios 在定位之前设置UILabel标注的动画

Ios 在定位之前设置UILabel标注的动画,ios,objective-c,animation,uilabel,frame,Ios,Objective C,Animation,Uilabel,Frame,我试图通过三个步骤将两个UIView(一个UIImageView和一个UILabel)一起制作动画: 0)两个视图都位于屏幕的左上角 1) 然后我改变了框架(也改变了字体大小的标签),使视图变得更大,位于中心 2) 我再次更改框架(以及标签字体大小),将两个视图都放在botton的右角。(此操作在几秒钟后开始) 3) 我从superview中删除这两个视图 UIImageView在每次动画之后都是完美的。对于UILabel,第一个动画有效,第二个则无效! 在第一个动画之后,我的标签立即变小,在延

我试图通过三个步骤将两个UIView(一个UIImageView和一个UILabel)一起制作动画:
0)两个视图都位于屏幕的左上角
1) 然后我改变了框架(也改变了字体大小的标签),使视图变得更大,位于中心 2) 我再次更改框架(以及标签字体大小),将两个视图都放在botton的右角。(此操作在几秒钟后开始)
3) 我从superview中删除这两个视图

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和label同时增长和移动(持续时间2秒)
这是真的

对于第一个动画,我希望:
-5秒钟内无任何内容(延迟)
-图像视图和标签变小并同时移动(持续3秒)
实际情况:
-标签立即更改尺寸
-5秒钟内无任何内容
-imageview变小并移动,标签移动 尝试将这些设置设置为标签:

[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisHorizontal];
[label setContentCompressionResistancePriority:UILayoutPriorityRequired forAxis:UILayoutConstraintAxisVertical];
它将避免被框架压缩(但不会变大)

尝试2:


尝试使用UITextView而不是UILabel,可能会更好,因为UITextView使用的contentView可能不会立即调整大小。

不相关,但我的眼睛会哭,因为要做所有这些
Try/catch
你正在做的事。如果您想捕获每个未捕获的异常以进行日志记录,那么当您说“第一个动画工作,但第二个动画不工作”时,只需使用
NSSetUncaughtExceptionHandler
设置一个异常处理程序,您不清楚这是什么意思。请详细说明发生了什么(或没有发生)。非常感谢@Gabriele!!!我编辑我的问题,我希望它是清晰的。我尝试过它,但行为是一样的:(尝试使用UITextView而不是UILabel,可能会更好,因为UITextView使用的contentView可能不会立即调整大小。事实上,我已经这样做了(我编辑了这个答案;))我很高兴它能工作:D