iOS 開發(fā)技巧 - UIViewController不讓導(dǎo)航欄遮擋控件

想必大家都遇到一種情況,明明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)了

最后編輯于
?著作權(quán)歸作者所有,轉(zhuǎn)載或內(nèi)容合作請聯(lián)系作者
平臺聲明:文章內(nèi)容(如有圖片或視頻亦包括在內(nèi))由作者上傳并發(fā)布,文章內(nèi)容僅代表作者本人觀點(diǎn),簡書系信息發(fā)布平臺,僅提供信息存儲服務(wù)。

推薦閱讀更多精彩內(nèi)容