gpt4 book ai didi

objective-c - animateWithDuration 不起作用

转载 作者:搜寻专家 更新时间:2023-10-30 20:10:30 26 4
gpt4 key购买 nike

我正在尝试使用一些按钮和 Controller 为我的主视图设置动画,以便从屏幕右侧进入屏幕。问题是它没有动画,它只是直接进入完成状态。

这是我的代码:

UIStoryboard* storyBoard = [UIStoryboard storyboardWithName:@"MainStoryboard" bundle:nil];
options = [storyBoard instantiateViewControllerWithIdentifier:@"OptionsView"];
options.delegate = self;
[self.view addSubview:options.view];
options.view.center = CGPointMake(floor(total_width+options.view.frame.size.width/2)+10, floor(total_height/2));

[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));
}
completion:^(BOOL finished){
NSLog(@"Done!");
}];

编辑

更奇怪的是,如果我将此动画放在另一个动画的完成 block 中,则此动画有效,但新动画无效。

    UIButton* boton = (UIButton*) sender;
[UIView animateWithDuration:5.0
delay:0.0
options: UIViewAnimationOptionCurveLinear
animations:^{
boton.alpha = 0.0;

//Jumps directly to 0, animation doesn't work

}
completion:^(BOOL finished){
[UIView animateWithDuration:0.5
delay:0.0
options: UIViewAnimationOptionCurveEaseInOut
animations:^{
options.view.center = CGPointMake(floor(total_width-options.view.frame.size.width/2)+10, floor(total_height/2));

//It works now, but it doesn't take 5 seconds to start, it starts right away

}
completion:^(BOOL finished){
NSLog(@"Done!");
}];

}];

最佳答案

animateWithDuration:... 调用之前的行直接将 center 分配给您正在设置动画的相同值。要么删除它,要么在那里分配初始 center 值。具有相同起始值和结束值的动画显然没有效果。

关于objective-c - animateWithDuration 不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11330758/

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