繁体   English   中英

推送viewController动画时,UINavigationController上的子视图看起来不正确

[英]Subview on UINavigationController when pushing viewController animated doesn't look right

在我的UIViewController viewDidLoad中,我有:

myButton = [UIButton buttonWithType:UIButtonTypeRoundedRect];
...
myButton.frame = CGRectMake(0, 2, 40, 40);
[self.navigationController.navigationBar addSubview:myButton];

按钮显示就好了。 不,我将另一个viewcontroller推入堆栈:

 [self.navigationController pushViewController:vc animated:YES];

当然,Button仍在显示,因此我尝试将其隐藏在viewWillDisappear中并在viewWillAppear中显示,但是过渡效果看起来不正确。 即使将超级调用的顺序与隐藏的调用互换,也看起来不正确。

- (void)viewWillDisappear:(BOOL)animated {
    [super viewWillDisappear:animated];
    myButton.hidden = YES;
}

- (void)viewWillAppear:(BOOL)animated {
    myButton.hidden = NO;
    [super viewWillAppear:animated];
}

我怎样做才能使过渡看起来正确? 谢谢。

与其将按钮添加为子视图,不如使用以下内容

UIBarButtonItem *barButton = [[UIBarButtonItem alloc] initWithCustomView:YourCustomView];
self.navigationItem.rightBarButtonItem = barButton;

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM