gpt4 book ai didi

ios - UIView 动画立即发生

转载 作者:行者123 更新时间:2023-11-28 18:30:59 25 4
gpt4 key购买 nike

我有一个包含三个按钮的动画,在我为按钮添加不同的可能位置之前,这些按钮可以正常工作。现在动画立即发生,但我不确定为什么。

这是一些代码:

defaults=[NSUserDefaults standardUserDefaults];
_btnCuenta3.hidden=NO;
CGPoint newPosition2;
CGPoint newPosition3;
CGPoint newPositionAgregar;
if([defaults objectForKey:@"cuenta3"]){
newPosition2=CGPointMake(200.0f + _btnCuenta2.frame.size.width/2.0f, _btnCuenta2.center.y);
newPosition3=CGPointMake(165.0f + _btnCuenta3.frame.size.width/2.0f, _btnCuenta3.center.y);
newPositionAgregar=CGPointMake(130.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnCuenta2.center=newPosition2;
_btnCuenta3.center=newPosition3;
_btnAgregar.center=newPositionAgregar;
}else if([defaults objectForKey:@"cuenta2"]){
newPosition2=CGPointMake(200.0f + _btnCuenta2.frame.size.width/2.0f, _btnCuenta2.center.y);
newPositionAgregar=CGPointMake(165.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnCuenta2.center=newPosition2;
_btnAgregar.center=newPositionAgregar;
}else{
newPositionAgregar=CGPointMake(200.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnAgregar.center=newPositionAgregar;
}
[UIView beginAnimations:nil context:nil];
[UIView setAnimationDuration:1.0f];
[UIView commitAnimations];

知道为什么会发生这种情况或我该如何解决它吗?

最佳答案

因为您没有制作任何动画。您只是在更改立即发生的属性。做这样的事情

[UIView animateWithDuration:1.0 animations:^{
if([defaults objectForKey:@"cuenta3"]){
newPosition2=CGPointMake(200.0f + _btnCuenta2.frame.size.width/2.0f, _btnCuenta2.center.y);
newPosition3=CGPointMake(165.0f + _btnCuenta3.frame.size.width/2.0f, _btnCuenta3.center.y);
newPositionAgregar=CGPointMake(130.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnCuenta2.center=newPosition2;
_btnCuenta3.center=newPosition3;
_btnAgregar.center=newPositionAgregar;
}else if([defaults objectForKey:@"cuenta2"]){
newPosition2=CGPointMake(200.0f + _btnCuenta2.frame.size.width/2.0f, _btnCuenta2.center.y);
newPositionAgregar=CGPointMake(165.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnCuenta2.center=newPosition2;
_btnAgregar.center=newPositionAgregar;
}else{
newPositionAgregar=CGPointMake(200.0f + _btnAgregar.frame.size.width/2.0f, _btnAgregar.center.y);
_btnAgregar.center=newPositionAgregar;
}

}];

关于ios - UIView 动画立即发生,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30629558/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com