我有一个让我疯狂的问题,我想我没有足够的知识来找到这个问题的答案.
这里有一个完美的代码:
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
你们有什么想法吗?我检查了约束和autoLayout,一切都很好.
试试这个 :
Objective-C的
[UIView animateWithDuration:0.3 delay:0.0 options:(UIViewAnimationOptionCurveLinear | UIViewAnimationOptionAllowUserInteraction) animations:^{ [imageList setCenter:CGPointMake(imageList.center.x, -imageList.center.y)]; } completion:nil];
斯威夫特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)