addView.autoresizingMask = mask;
mask 是UIViewAutoresizing的类型
这是我的定义,
#define FlexibleT UIViewAutoresizingFlexibleTopMargin
#define FlexibleB UIViewAutoresizingFlexibleBottomMargin
#define FlexibleL UIViewAutoresizingFlexibleLeftMargin
#define FlexibleR UIViewAutoresizingFlexibleRightMargin
#define FlexibleH UIViewAutoresizingFlexibleHeight
#define FlexibleW UIViewAutoresizingFlexibleWidth
#define FixedMarginT FlexibleW | FlexibleB
#define FixedMarginB FlexibleW | FlexibleT
#define FixedMarginL FlexibleH | FlexibleR
#define FixedMarginR FlexibleH | FlexibleL
#define FixedHorizental FlexibleW | FlexibleT | FlexibleB
#define FixedVertical FlexibleH | FlexibleL | FlexibleR
#define FixedALL FlexibleW | FlexibleH
#define FixedCenter FlexibleL | FlexibleR | FlexibleT | FlexibleB
你可以这样设置
addView.autoresizingMask = FixedVertical;