想必大家都遇到一种情况,明明y坐标设置的是0,但是总是被讨厌的导航栏给遮住。比如下面这个情况:
先创建测试用按钮
UIButton *button = [UIButton buttonWithType:UIButtonTypeCustom];
[button setTitle:@"点击" forState:UIControlStateNormal];
[button setTitleColor:[UIColor blackColor] forState:UIControlStateNormal];
[self.view addSubview:button];
button.frame = CGRectMake(0, 0, 100, 30);
运行看效果:
在iOS7之后,UIViewController 引入了一个新的属性:edgesForExtendedLayout
@property(nonatomic,assign) UIRectEdge edgesForExtendedLayout NS_AVAILABLE_IOS(7_0); // Defaults to UIRectEdgeAll
默认情况下是UIRectEdgeAll = UIRectEdgeTop | UIRectEdgeLeft | UIRectEdgeBottom | UIRectEdgeRight 表示上下左右都填充
修改方法:修改edgesForExtendedLayout的默认值
self.edgesForExtendedLayout = UIRectEdgeNone;
运行看效果:
ok,这样就能修改起始坐标了