Ios animateWithDuration设置帧不工作

Ios animateWithDuration设置帧不工作,ios,uiview,uiviewanimation,Ios,Uiview,Uiviewanimation,嗨,我有一段代码,其中只有一行不工作 [UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{ [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working [self.currentLabel setFrame:CGRectOffset

嗨,我有一段代码,其中只有一行不工作

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working
    [self.currentLabel setFrame:CGRectOffset(self.currentLabel.frame, frame.size.width, 0)]; //not working 
    [self.currentLabel setAlpha:0.0f]; //working
} completion:^(BOOL finished) {
    [self.currentLabel removeFromSuperview];
    self.currentLabel = label;
}];

我想不出怎么回事了…

帧必须是一个带有4个参数的
CGRect
(xPosition、yPosition、width、height)。对设置帧使用
CGRectMake

self.currentLabel.frame = CGRectMake(100, 100, self.currentLabel.frame.size.width, self.currentLabel.frame.size.height)

将动画持续时间设置为0.3秒,并在动画结束时将其从视图中删除。这个太短了。设置示例2的持续时间,您将看到标签正在移动。

有时您也应该在动画之后设置视图动画帧,例如在完成块中,尝试类似的操作

[UIView animateWithDuration:0.3 delay:0.0 options:UIViewAnimationOptionCurveEaseOut animations:^{
    [label setFrame:CGRectMake(0, 0, frame.size.width, kStandardLabelHeight)]; //working
    [self.currentLabel setFrame:CGRectOffset(self.currentLabel.frame, frame.size.width, 0)]; //not working 
    [self.currentLabel setAlpha:0.0f]; //working
} completion:^(BOOL finished) {
    self.frame = currentLabelFrame;
    label.frame = label.frame;
    [self.currentLabel removeFromSuperview];
    self.currentLabel = label;
}];

我发现:如果我关闭“使用自动布局”,它会神奇地工作,所以这个问题与自动布局有关

搜索后,我发现:

为视图添加约束输出映射,然后更新约束而不是使用setFrame就可以了

下面是我的最终实现(_topConstraint是表视图的顶部垂直空间约束):

-(iAction)开关按钮已触动:(id)发送方
{

如果(_topConstraint.constant如果您的问题与Autolayout或此处列出的其他问题无关,那么还有一个可能的问题是我的问题。我正在占用相同屏幕空间的视图上同时运行UIView转换(transitionFromView:到View:)(不同的超视图,不相关,但定位在总体视图控制器的超视图中除外)

我的代码如下所示:

[UIView transitionFromView:self.someView
                    toView:self.someOtherView
                  duration:0.6f 
                   options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionShowHideTransitionViews 
                completion:NULL];

[UIView animateWithDuration:0.3
                      delay:0.0 options:UIViewAnimationOptionCurveEaseOut 
                  animations:^{
                        [self.someThirdView setFrame:someFrame]; //not working 
                        [self.someThirdView setAlpha:1.0f]; //working
                } completion:nil];
帧已更改,但它弹出到新帧,而不是动画。我猜这是iOS内部的问题。我删除了“transitionFromView:…”调用后,帧动画工作正常


目前我的解决方案是将第二个动画移动到transitionFromView的完成块中。这并不完美,因为两个动画应该已经对齐,但目前这是一个可以接受的解决方案。

self.currentLabel.frame=CGRectMake(100100,self.currentLabel.frame.size.width,self.currentLabel.frame.size.height)您将动画持续时间设置为0.3秒,当动画结束时,您将其从视图中删除。这太短了。将持续时间设置为示例2,您将看到标签正在移动。我也有同样的问题。我假设是故事板或xib,对吗?如果是,请转到您的xib或该视图的故事板,取消选择“useAutolayout”。我在某处有图片,我必须找到它。找到它:
[UIView transitionFromView:self.someView
                    toView:self.someOtherView
                  duration:0.6f 
                   options:UIViewAnimationOptionTransitionCrossDissolve | UIViewAnimationOptionShowHideTransitionViews 
                completion:NULL];

[UIView animateWithDuration:0.3
                      delay:0.0 options:UIViewAnimationOptionCurveEaseOut 
                  animations:^{
                        [self.someThirdView setFrame:someFrame]; //not working 
                        [self.someThirdView setAlpha:1.0f]; //working
                } completion:nil];