如何在UINavigationBar上显示UIView

时间:2015-03-10 16:27:06

标签: ios objective-c xcode uiview

有没有人有任何优雅的解决方案可以在UINavigationBar前面移动UIView?

我希望发生以下情况:

1 - 单击绿色按钮

2 - 绿色按钮和蓝色视图向上滑动到UINavigationBar

3 - 绿色按钮停留在UINavigationBar

之上

enter image description here

1 个答案:

答案 0 :(得分:1)

不是最优雅的解决方案,但我认为您需要从其当前视图层次结构中删除该按钮并将其添加到导航控制器视图中。

e.g。

- (void)buttonPress:(UIButton *)sender {

    [UIView animateWithDuration:0.3 animations:^{
        [sender removeFromSuperview];
        [self.navigationController.view addSubview:sender];
        [sender setFrame:CGRectMake(sender.frame.origin.x, self.navigationController.navigationBar.frame.origin.y, sender.frame.size.width, sender.frame.size.height)];
    }];

}