[英]ViewController goes black when pushing it in UINavigationcontroller stack
[英]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.