我正在设计故事板中的视图控制器。它包含顶部的导航栏和内容视图。我已将约束设置为
因为我想显示状态栏,所以我使用顶部布局指南使导航栏显示在其下方。它适用于标准的UINavigationBar。
但我有自定义导航栏:我创建了自己的继承UINavigationBar的类。
问题是:在界面构建器的Identity Inspector中为导航栏指定此自定义类时,在运行应用程序时,该栏不在正确的位置。
是否需要在initWitFrame
或initWithCoder
中添加或修改任何内容,或其他要做的事情,因此我的自定义导航栏将遵循故事板的限制。
编辑 - 已添加来源
- (id)initWithFrame:(CGRect)frame
{
self = [super initWithFrame:frame];
if (self) {
// additional setup
}
return self;
}
- (id)initWithCoder:(NSCoder *)aDecoder
{
self = [super initWithCoder:(NSCoder *)aDecoder];
if (self) {
// same setup than initWithFrame:
}
return self;
}
- (void)drawRect:(CGRect)rect
{
//[self setFrame:rect]; navigation bar is not at the right place if uncommented
}
答案 0 :(得分:0)
你为什么打电话给[self setFrame:rect];
?此时frame
已正确设置,您不应更改它。此外,rect
位于导航栏的内部坐标系中。