Ios 如何交换2个UIButton的位置
我想在按下特定按钮时交换2个Ios 如何交换2个UIButton的位置,ios,objective-c,uibutton,autolayout,Ios,Objective C,Uibutton,Autolayout,我想在按下特定按钮时交换2个ui按钮的位置。这是我的密码。它们都受到Autolayout CGRect tempFrame=_flightButton.frame; UIViewAutoresizing tempResize=_flightButton.autoresizingMask; [_flightButton setFrame:_contactButton.frame]; [_flightButton setAutoresizingMask:_contactBu
ui按钮的位置。这是我的密码。它们都受到Autolayout
CGRect tempFrame=_flightButton.frame;
UIViewAutoresizing tempResize=_flightButton.autoresizingMask;
[_flightButton setFrame:_contactButton.frame];
[_flightButton setAutoresizingMask:_contactButton.autoresizingMask];
[_contactButton setFrame:tempFrame];
[_contactButton setAutoresizingMask:tempResize];
我也试过这个。交换约束。这也不管用
NSArray *tempConstraints=_flightButton.constraints;
[_flightButton removeConstraints:_flightButton.constraints];
[_flightButton addConstraints:_contactButton.constraints];
[_contactButton removeConstraints:_contactButton.constraints];
[_contactButton addConstraints:tempConstraints];
如果使用“自动布局”,则需要修改约束,而不是更改框架或调整遮罩的大小。在情节提要中创建两组约束,其中一组被禁用。如果要交换按钮,请禁用一组约束并启用另一组约束。如果使用的是自动布局
,请尝试不要手动设置帧,而是更改约束的。常量
属性。我可以交换约束吗?例如,将ButtonOne的约束分配给ButtonTwo,反之亦然?是的,您可以交换约束。请检查编辑