2016-12-05 3 views
1

Я пытаюсь сделать простой NSTouchBar с 3 уровнями NSPopoverTouchBarItem, поэтому в основном его, как это:NSTouchBar с многоуровневым NSPopoverTouchBarItem

touchbar У меня есть главный NSTouchbar с 3 NSButton и 1 NSPopoverTouchBarItem открывающие второй NSTouchbar

Второй NSTouchbar с 2 NSButton и 1 NSPopoverTouchBarItem которые открывают третий NSTouchbar

Проблема в том, когда я пытаюсь открыть 3-й NSTouchbar, кажется, что 2-й NSTouchbar уволен, а иногда и не открывает 3-й.

Кроме того, когда откроется третий, когда мы закрываем, мы идем в 1-й NSTouchbar, а не второй NSTouchbar

Вот код, должен быть простым, и должны работать (я использую Xcode сенсорной панели Simulator)

#import "Window.h" 

static NSTouchBarCustomizationIdentifier TouchBarCustomizationIdentifier = @"TouchBarCustomizationIdentifier"; 

static NSTouchBarItemIdentifier NSTouchBarItemIdentifier1     = @"NSTouchBarItemIdentifier1"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier2     = @"NSTouchBarItemIdentifier2"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier3     = @"NSTouchBarItemIdentifier3"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4     = @"NSTouchBarItemIdentifier4"; 

static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4_1     = @"NSTouchBarItemIdentifier4_1"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4_2     = @"NSTouchBarItemIdentifier4_2"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4_3     = @"NSTouchBarItemIdentifier4_3"; 

static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4_3_1    = @"NSTouchBarItemIdentifier4_3_1"; 
static NSTouchBarItemIdentifier NSTouchBarItemIdentifier4_3_2    = @"NSTouchBarItemIdentifier4_3_2"; 

@implementation Window 

- (NSTouchBar*) makeTouchBar { 

    _touchBar1 = [[NSTouchBar alloc] init]; 
    [_touchBar1 setDelegate:self]; 
    [_touchBar1 setCustomizationIdentifier:TouchBarCustomizationIdentifier]; 

    [_touchBar1 setDefaultItemIdentifiers:@[ 
              NSTouchBarItemIdentifier1, 
              NSTouchBarItemIdentifier2, 
              NSTouchBarItemIdentifier3, 
              NSTouchBarItemIdentifier4, 
              ] 
    ]; 
    [_touchBar1 setCustomizationRequiredItemIdentifiers:@[ 
                  NSTouchBarItemIdentifier1, 
                  NSTouchBarItemIdentifier2, 
                  NSTouchBarItemIdentifier3, 
                  NSTouchBarItemIdentifier4, 
                  ] 
    ]; 

    return _touchBar1; 
} 

- (nullable NSTouchBarItem *)touchBar:(NSTouchBar *)touchBar makeItemForIdentifier:(NSTouchBarItemIdentifier)identifier { 

    if ([identifier isEqual:NSTouchBarItemIdentifier1]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 
     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH 1" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier2]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH1" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier3]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH1" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4]) { 

     NSPopoverTouchBarItem *customTouchBarItem = [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]; 
     [customTouchBarItem setCollapsedRepresentationLabel:@"OPEN TOUCH 2"]; 

     _touchBar2 = [[NSTouchBar alloc] init]; 
     [_touchBar2 setDelegate:self]; 
     [_touchBar2 setCustomizationIdentifier:TouchBarCustomizationIdentifier]; 

     [_touchBar2 setDefaultItemIdentifiers:@[ 
               NSTouchBarItemIdentifier4_1, 
               NSTouchBarItemIdentifier4_2, 
               NSTouchBarItemIdentifier4_3, 
               ] 
     ]; 
     [_touchBar2 setCustomizationRequiredItemIdentifiers:@[ 
                   NSTouchBarItemIdentifier4_1, 
                   NSTouchBarItemIdentifier4_2, 
                   NSTouchBarItemIdentifier4_3, 
                   ] 
     ]; 

     [customTouchBarItem setPopoverTouchBar:_touchBar2]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4_1]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH 2" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4_2]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH 2" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4_3]) { 

     NSPopoverTouchBarItem *customTouchBarItem = [[NSPopoverTouchBarItem alloc] initWithIdentifier:identifier]; 
     [customTouchBarItem setCollapsedRepresentationLabel:@"OPEN TOUCH 3"]; 

     _touchBar3 = [[NSTouchBar alloc] init]; 
     [_touchBar3 setDelegate:self]; 
     [_touchBar3 setCustomizationIdentifier:TouchBarCustomizationIdentifier]; 

     [_touchBar3 setDefaultItemIdentifiers:@[ 
               NSTouchBarItemIdentifier4_3_1, 
               NSTouchBarItemIdentifier4_3_2, 
               ] 
     ]; 
     [_touchBar3 setCustomizationRequiredItemIdentifiers:@[ 
                   NSTouchBarItemIdentifier4_3_1, 
                   NSTouchBarItemIdentifier4_3_2, 
                   ] 
     ]; 

     [customTouchBarItem setPopoverTouchBar:_touchBar3]; 


     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4_3_1]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH 3" target:self action:nil]]; 

     return customTouchBarItem; 

    } else if ([identifier isEqual:NSTouchBarItemIdentifier4_3_2]) { 

     NSCustomTouchBarItem *customTouchBarItem = [[NSCustomTouchBarItem alloc] initWithIdentifier:identifier]; 

     [customTouchBarItem setView:[NSButton buttonWithTitle:@"IS TOUCH 3" target:self action:nil]]; 

     return customTouchBarItem; 

    } 

    return nil; 
} 

@end 
+0

Это выглядит как ошибка в SDK Apple. Другая причина заключается в том, что я не могу найти системные сенсорные панели с двумя уровнями popovers, как вы пытаетесь реализовать. Я предлагаю использовать Scrubber, как в [NSTouchBar Catalog] в Apple (https://developer.apple.com/library/content/samplecode/NSTouchBarCatalog/Introduction/Intro.html#//apple_ref/doc/uid/TP40017550), чтобы поместите больше предметов только в два уровня popovers (по крайней мере, до тех пор, пока они не исправит его). –

ответ

0

Apple, говорит Popovers не может иметь Popovers, так что вы можете иметь только бар и поповер, а не поповер внутри пирог.

Это то, что они выложили в своем форуме, чтобы ответить на подобный вопрос:

enter image description here

https://forums.developer.apple.com/thread/78730

Смежные вопросы