我姗姗来迟地看着Autolayout
。通常我会根据UIView的框架制作动画(即我已经使用了以下内容):
NSArray *sortedArray = [self.buttonArray sortedArrayUsingDescriptors:[NSArray arrayWithObject:ascendingSort]];
for (int i = 0;i<sortedArray.count;i++) {
UIButton * theButton = [sortedArray objectAtIndex:i];
[UIView animateWithDuration:1 delay:i *0.05 usingSpringWithDamping:10 initialSpringVelocity:20 options:UIViewAnimationOptionCurveEaseIn animations:^{
[theButton setFrame:frameToAnimateTo];
} completion:nil];
}
我是否正确地认为我现在必须根据按钮约束的常量属性进行动画处理?
NSArray *sortedArray = [self.ButtonHorizonalConstraints sortedArrayUsingDescriptors:[NSArray arrayWithObject:ascendingSort]];
for (int i = 0;i 'less than' sortedArray.count;i++) {
NSLayoutConstraint * constraint = [sortedArray objectAtIndex:i];
UIButton * theButton = constraint.firstItem;
constraint.constant = toShow?0:-theButton.frame.size.width;
[self.view setNeedsUpdateConstraints];
[UIView animateWithDuration:1 delay:i *(toShow?0.1:0.05) usingSpringWithDamping:10 initialSpringVelocity:toShow?20:-20
options:UIViewAnimationOptionCurveEaseIn animations:^{
[self.view layoutIfNeeded];
} completion:nil]; }
我得到的最终结果是我想要的,但是在构造代码的方面似乎不对。