Пытаюсь сделать анимацию просмотра индикатора панели навигации.В макете есть некоторые проблемы.
Ожидает этого:
![1](https://i.stack.imgur.com/zvcLc.png)
Мое решение состоит в том, чтобы преобразовать позицию в нижней позиции панели навигации вself.navigationItem.titleView
.
Вид индикатора панели навигации должен принадлежать контроллеру вида.Не навигационный контроллер.Таким образом, индикатор находится на self.navigationItem.titleView
.
, в то время как его позиция находится внизу панели навигации.Положение Y - это точка (0, 64).
Поэтому мне нужен метод convertPoint: toView:
.Вот код:
- (void)setupTitlesView
{
UIView *titlesView = [[UIView alloc] initWithFrame: CGRectMake(0, 0, 100, 35)];
self.navigationItem.titleView = titlesView;
CGPoint new_point = [self.view convertPoint: CGPointMake(0, 64) toView: self.navigationItem.titleView];
NSLog(@"\n\n%@\n\n", NSStringFromCGPoint(new_point));
UIView *indicatorView = [[UIView alloc] initWithFrame: CGRectMake(0, new_point.y - 2, 0, 2)];
indicatorView.tag = -1;
self.indicatorView = indicatorView;
NSArray *titles = @[@"商品", @"详情"];
CGFloat width = titlesView.frame.size.width / titles.count;
CGFloat height = titlesView.frame.size.height;
for (NSInteger i = 0; i<titles.count; i++) {
UIButton *button = [[UIButton alloc] initWithFrame: CGRectMake(i*width, 0, width, height)];
button.tag = i;
[button setTitle:titles[i] forState:UIControlStateNormal];
// color , font ...
[titlesView addSubview:button];
// default click
if (i == 0) {
button.enabled = NO;
self.selectedButton = button;
[button.titleLabel sizeToFit];
CGRect tempFrame = self.indicatorView.frame;
tempFrame.size.width = button.titleLabel.frame.size.width;
self.indicatorView.frame = tempFrame;
CGPoint tempCenter = self.indicatorView.center;
tempCenter.x = button.center.x;
self.indicatorView.center = tempCenter;
}
}
[titlesView addSubview: indicatorView];
}
Результат выводит:
{0, 64}
Apple говорит:
convertPoint: toView: преобразует точку из системы координат получателя в систему координат указанного вида.
Как это исправить?