UIview.hidden не исчезает, а прячется за другим видом - PullRequest
0 голосов
/ 26 мая 2018

Итак, я пытаюсь скрыть UIView, но происходит нечто странное.После использования этой строки кода:

ntcCircleView.hidden = YES;

Представление не исчезнет, ​​но будет скрыто за другим UIView.

Это полный код, который я использую:

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];

Итак, ntcCircleView после его скрытия просто идет за messagesImage .

Что сводит меня с ума, так это то, что я успешно использую точно такой же код в других представлениях, с той лишь разницей, что в последней строке.Вместо использования:

[self.view addSubview:NtcContainer];

Я добавляю виды на панель навигации следующим образом:

UIBarButtonItem *ntcBarItem = [[UIBarButtonItem alloc] initWithCustomView:NtcContainer];
self.navigationItem.rightBarButtonItem = ntcBarItem;

Что мне здесь не хватает?

ОБНОВЛЕНИЕ

Я также заметил, что эта ошибка возникает, только когда я использую

[self.navigationController popViewControllerAnimated:YES];

, чтобы вернуться к представлению.

Ответы [ 2 ]

0 голосов
/ 29 мая 2018

Я понял это.Я использовал устаревший метод (viewDidUnload), чтобы освободить наблюдателя уведомления.

0 голосов
/ 28 мая 2018

Вам нужно обновить этот фрагмент:

[NtcView addSubview:notificationImage];
[NtcView addSubview:notificationButton];
[NtcView addSubview:ntcCircleView];
[NtcContainer addSubview:NtcView];

до:

[NtcView addSubview:notificationButton];
[NtcView addSubview:ntcCircleView];
[NtcView addSubview:notificationImage];
[NtcContainer addSubview:NtcView];

Это решит вашу проблему.

Добро пожаловать на сайт PullRequest, где вы можете задавать вопросы и получать ответы от других членов сообщества.
...