[英]UIview.hidden doesn't disappear but hides behind another view
So I am trying to hide a UIView but something weird is happening. 所以我试图隐藏一个UIView但发生了一些奇怪的事情。 After using this line of code:
使用此行代码后:
ntcCircleView.hidden = YES;
The view won't disappear, but it hides behind another UIView. 该视图不会消失,但隐藏在另一个UIView的后面。
This is the complete code I use: 这是我使用的完整代码:
UIView* NtcContainer=[[UIView alloc]initWithFrame:CGRectMake(self.view.frame.size.width - 40-17, 3, 40, 40)];
UIView* NtcView=[[UIView alloc]initWithFrame:CGRectMake(5, 0, 40, 40)];
notificationButton = [ZFRippleButton buttonWithType:UIButtonTypeCustom];
notificationButton.frame = CGRectMake(0, 0, 40, 40);
notificationButton.layer.cornerRadius=menuButton.frame.size.width/2;
[notificationButton addTarget:self action:@selector(goToNotificationsList:) forControlEvents:UIControlEventTouchUpInside];
notificationImage=[[UIImageView alloc]initWithFrame:CGRectMake(10, 12, 20, 20)];
notificationImage.image=[UIImage imageNamed:[HotelStay sharedInstance].icon.Notification];
ntcCircleView = [[UIView alloc] initWithFrame:CGRectMake(20,5,16,16)];
ntcCircleView.alpha = 0.7;
ntcCircleView.layer.cornerRadius = ntcCircleView.frame.size.width/2; // half the width/height
ntcCircleView.backgroundColor = [UIColor redColor];
ntcNumberLabel = [[UILabel alloc] initWithFrame:CGRectMake(0,0,16,16)];
ntcNumberLabel.textAlignment = NSTextAlignmentCenter;
[ntcNumberLabel setTextColor:[UIColor whiteColor]];
[ntcNumberLabel setFont:[UIFont fontWithName:@"HelveticaNeue" size:11.0]];
[ntcCircleView addSubview:ntcNumberLabel];
int ntcNum = [dataManager getUnreadNotificationNumber];
if (ntcNum==0)
{
ntcCircleView.hidden = YES;
}else
{
ntcNumberLabel.text = [NSString stringWithFormat:@"%i",ntcNum];
}
[NtcView addSubview:notificationImage];
[NtcView addSubview:notificationButton];
[NtcView addSubview:ntcCircleView];
[NtcContainer addSubview:NtcView];
[self.view addSubview:NtcContainer];
So ntcCircleView after hidding it, just goes behind notificationImage . 所以ntcCircleView隐藏之后,仅在notificationImage之后 。
What drives me crazy, is that I use successfully the exact same code in another Views with the only difference the last line. 使我发疯的是,我成功地在另一个视图中使用了完全相同的代码,而最后一行只是不同之处。 Instead of using:
而不是使用:
[self.view addSubview:NtcContainer];
I add the views to the navigation bar like this: 我将视图添加到导航栏中,如下所示:
UIBarButtonItem *ntcBarItem = [[UIBarButtonItem alloc] initWithCustomView:NtcContainer];
self.navigationItem.rightBarButtonItem = ntcBarItem;
What am I missing here ? 我在这里想念什么?
UPDATE UPDATE
I also noticed that this bug happens only when I use 我还注意到只有在使用时才会发生此错误
[self.navigationController popViewControllerAnimated:YES];
to navigate back to the view. 导航回到视图。
You need to update these snippet: 您需要更新以下代码段:
[NtcView addSubview:notificationImage];
[NtcView addSubview:notificationButton];
[NtcView addSubview:ntcCircleView];
[NtcContainer addSubview:NtcView];
to: 至:
[NtcView addSubview:notificationButton];
[NtcView addSubview:ntcCircleView];
[NtcView addSubview:notificationImage];
[NtcContainer addSubview:NtcView];
It will solve your problem. 它将解决您的问题。
I figured it out. 我想到了。 I was using a deprecated method (viewDidUnload) to release the notification observer.
我正在使用不推荐使用的方法(viewDidUnload)释放通知观察器。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.