我正在尝试实现一个下拉视图,当用户按下按钮时它将向下移动,一旦用户按下相同的按钮,它将再次上升.我为此目的使用以下代码:
[UIView animateWithDuration:0.25f animations:^{
self.dropdownView.frame =
CGRectMake(self.dropdownView.frame.origin.x,
self.dropdownView.frame.origin.y+42,
self.dropdownView.frame.size.width,
self.dropdownView.frame.size.height);
}
completion:^(BOOL finished){
NSLog(@"%@",self.dropdownView);
}];
Run Code Online (Sandbox Code Playgroud)
我在这里尝试的是将原点42点向下移动以创建下拉类型的动画.如果向上移动,我正在使用:
[UIView animateWithDuration:0.25f animations:^{
self.dropdownView.frame =
CGRectMake(self.dropdownView.frame.origin.x,
self.dropdownView.frame.origin.y-42,
self.dropdownView.frame.size.width,
self.dropdownView.frame.size.height);
}
completion:^(BOOL finished){
NSLog(@"%@",self.dropdownView);
}];
Run Code Online (Sandbox Code Playgroud)
但是,如果我检查日志,则不会更新下拉视图的框架.但是,如果我在具有不同UI元素的另一个VC中使用相同的代码,则此代码工作正常.在这两种情况下,我都在故事板中创建了下拉视图.代码有什么问题,以致它无法正常工作?
编辑
当我在第一个动画之前记录约束时,日志是:
Constraints: (
"<NSIBPrototypingLayoutConstraint:0x7fcb01797460 'IB auto generated at build time for view with fixed frame' H:|-(0)-[UIImageView:0x7fcb01481970](LTR) (Names: '|':UIView:0x7fcb014a16b0 )>",
"<NSIBPrototypingLayoutConstraint:0x7fcb017c0ac0 'IB auto generated at build time for view with fixed frame' V:|-(0)-[UIImageView:0x7fcb01481970] (Names: '|':UIView:0x7fcb014a16b0 )>",
"<NSIBPrototypingLayoutConstraint:0x7fcb017c0b10 'IB auto generated at build time for view with fixed frame' H:[UIImageView:0x7fcb01481970(320)]>", …Run Code Online (Sandbox Code Playgroud)