想必大家都遇到一種情況,明明y坐標(biāo)設(shè)置的是0,但是總是被討厭的導(dǎo)航欄給遮住。比如下面這個情況:
先創(chuàng)建測試用按鈕
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"點(diǎn)擊" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:button];
button.frame = CGRectMake(0, 0, 100, 30);
運(yùn)行看效果:
在iOS7之后,UIViewController 引入了一個新的屬性:edgesForExtendedLayout
@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll
默認(rèn)情況下是UIRectEdgeAll? ? = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight 表示上下左右都填充
修改方法:修改edgesForExtendedLayout的默認(rèn)值
self.edgesForExtendedLayout = UIRectEdgeNone;
運(yùn)行看效果:
ok,這樣就能修改起始坐標(biāo)了