gpt4 book ai didi

iOS - UIView setCenter 在 UIView animateWithDuration 中不起作用

转载 作者:行者123 更新时间:2023-11-28 18:17:00 26 4
gpt4 key购买 nike

我遇到了一个让我发疯的问题,我想我没有足够的知识来找到这个问题的答案。

这里是一个完美运行的代码:

NSLog(@"%f, %f", imageList.center.x, imageList.center.y);
[imageList setCenter:CGPointMake(imageList.center.x, -imageList.center.y)];
NSLog(@"=> %f, %f", imageList.center.x, imageList.center.y);

给我以下输出:

2016-01-08 11:48:42.585 User[4047:600095] 160.000000, 284.000000
2016-01-08 11:48:42.585 User[4047:600095] => 160.000000, -284.000000

现在,如果我把这个 setCenter 放到 UIView animationWithDuration 中,就像这样

NSLog(@"%f, %f", imageList.center.x, imageList.center.y);
[UIView animateWithDuration:0.3 animations:^{
[imageList setCenter:CGPointMake(imageList.center.x, -imageList.center.y)];
} completion:^(BOOL finished) {*/
NSLog(@"=> %f, %f", imageList.center.x, imageList.center.y);
}];

我得到这个输出:

2016-01-08 11:48:42.585 User[4047:600095] 160.000000, 284.000000
2016-01-08 11:48:42.585 User[4047:600095] => 160.000000, 284.000000

你们知道为什么吗?我检查了约束和自动布局,一切都很好。

最佳答案

试试这个:

objective-C

[UIView animateWithDuration:0.3 delay:0.0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{
[imageList setCenter:CGPointMake(imageList.center.x, -imageList.center.y)];
} completion:nil];

swift 4

UIView.animate(withDuration: 0.3, delay: 0.0, options: .curveLinear, animations: {
imageList.center = CGPoint(x: imageList.center.x, y: -imageList.center.y)
}, completion: nil)

关于iOS - UIView setCenter 在 UIView animateWithDuration 中不起作用,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34675333/

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