在布局代码中感到窒息?使用这些辅助工具在常见情况下可减少高达75%的布局代码。请查看.h文件以获取完整的接口。
CGRect frame = myView.frame;
frame.origin.x = ...
frame.origin.y = ...
myView.frame = frame;
[myView setX:myXVal andY:myYVal];
CGRect frame = myView.frame;
frame.origin.x = frame.origin.x + xDelta;
frame.origin.y = frame.origin.y + yDelta;
myView.frame = frame;
[myView adjustX:xDelta andY:yDelta];
CGRect frame = myView.frame;
frame.origin.x = myOtherView.origin.x + myOtherView.size.width + kMyPaddingConst;
frame.origin.y = myOtherView.origin.y;
myView.frame = frame;
[myView insideTopEdgeOfSuperviewBy:0];
[myView outsideRightEdgeOf:myOtherView by:kMyPaddingConst];
如果正在使用相对定位辅助工具,例如 insideSomeEdgeOfSuperviewBy: 或 outsideOtherEdgeOf:by:,确保在将接收器添加到其父视图后再调用它们。
更通用的 inside/outsideOf:by: 方法不依赖于视图层次结构的配置。