Anfängerfehler: NSView in Subklasse von NSView einfügen.

Diese Seite verwendet Cookies. Durch die Nutzung unserer Seite erklären Sie sich damit einverstanden, dass wir Cookies setzen. Weitere Informationen

  • Ich versuche das Collapse Verhalten eines NSSplitViews zu animieren wenn man auf einen Button klickt. Jedoch funktioniert es leider nicht.
    Was ist mein Fehler ? Kann mir jemand helfen ?

    Quellcode

    1. -(IBAction)toggle:(id)sender{
    2. if ([self isSubviewCollapsed:[[self subviews] objectAtIndex:0]]) {
    3. NSView* topView = [[self subviews] objectAtIndex:0];
    4. NSView* bottomView = [[self subviews] objectAtIndex:1];
    5. NSMutableDictionary* expandBottomViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
    6. [expandBottomViewDict setObject:bottomView forKey:NSViewAnimationTargetKey];
    7. NSRect newBottomFrame = bottomView.frame;
    8. newBottomFrame.size.height = self.frame.size.height -130;
    9. [expandBottomViewDict setObject:[NSValue valueWithRect:newBottomFrame] forKey:NSViewAnimationEndFrameKey];
    10. NSMutableDictionary* expandTopViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
    11. [expandTopViewDict setObject:topView forKey:NSViewAnimationTargetKey];
    12. NSRect newTopViewFrame = topView.frame;
    13. newTopViewFrame.size.height = 120;
    14. newTopViewFrame.origin.y = self.frame.size.height;
    15. [expandTopViewDict setObject:[NSValue valueWithRect:newTopViewFrame] forKey:NSViewAnimationEndFrameKey];
    16. NSViewAnimation *expandAnimation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:expandBottomViewDict, expandTopViewDict, nil]];
    17. [expandAnimation setDuration:0.25f];
    18. [expandAnimation startAnimation];
    19. }
    20. }
    Alles anzeigen
  • Bzw. jetzt habe ich es hinbekommen, aber die Animation läuft total schlecht und nicht schön flüssig. Was mache ich den hier falsch ? Oder ist es ein Bug ?

    Quellcode

    1. -(IBAction)toggle:(id)sender{
    2. if ([self isSubviewCollapsed:[[self subviews] objectAtIndex:0]]) {
    3. NSView* topView = [[self subviews] objectAtIndex:0];
    4. NSView* bottomView = [[self subviews] objectAtIndex:1];
    5. [topView setHidden:NO];
    6. [bottomView setHidden:NO];
    7. NSRect topViewFrame = [topView frame];
    8. NSRect bottomViewFrame = [bottomView frame];
    9. bottomViewFrame.origin.y = 120 + [self dividerThickness];
    10. bottomViewFrame.size.height = self.frame.size.height - 120 - [self dividerThickness];
    11. NSMutableDictionary* topViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
    12. [topViewDict setObject:topView forKey:NSViewAnimationTargetKey];
    13. [topViewDict setObject:[NSValue valueWithRect:topViewFrame] forKey:NSViewAnimationEndFrameKey];
    14. NSMutableDictionary* bottomViewDict = [NSMutableDictionary dictionaryWithCapacity:2];
    15. [bottomViewDict setObject:bottomView forKey:NSViewAnimationTargetKey];
    16. [bottomViewDict setObject:[NSValue valueWithRect:bottomViewFrame] forKey:NSViewAnimationEndFrameKey];
    17. NSViewAnimation *collapseAnimation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:bottomViewDict, topViewDict, nil]];
    18. [collapseAnimation setDuration:2.0f];
    19. [collapseAnimation startAnimation];
    20. }
    21. }
    Alles anzeigen
  • Rege Beteiligung hier ^^

    Mittlerweile habe ich es selbst herausgefunden. Wenn ein Teil des SplitViews eingefahren ist, so ist es "verborgen" (Hidden: YES).
    Wenn die obige Animation läuft, dann wird hide auf NO gestellt und dann animiert. Das sieht nicht flüssig aus.

    Für alle die vor dem gleichen Problem stehen, funktioniert der folgende Code:

    Quellcode

    1. if ([self isSubviewCollapsed:[[self subviews] objectAtIndex:0]]) {
    2. [[self subviews] objectAtIndex:0].hidden = NO;
    3. [[self subviews] objectAtIndex:1].hidden = NO;
    4. [[[self subviews] objectAtIndex:0] setFrameSize:NSMakeSize(0, 0)];
    5. NSMutableDictionary *expandMainAnimationDict = [NSMutableDictionary dictionaryWithCapacity:2];
    6. [expandMainAnimationDict setObject:[[self subviews] objectAtIndex:1] forKey:NSViewAnimationTargetKey];
    7. NSRect newMainFrame = NSMakeRect(0, 120 + self.dividerThickness, self.frame.size.width, self.frame.size.height - 120 - self.dividerThickness);
    8. [expandMainAnimationDict setObject:[NSValue valueWithRect:newMainFrame] forKey:NSViewAnimationEndFrameKey];
    9. NSMutableDictionary *expandInspectorAnimationDict = [NSMutableDictionary dictionaryWithCapacity:2];
    10. [expandInspectorAnimationDict setObject:[[self subviews] objectAtIndex:0] forKey:NSViewAnimationTargetKey];
    11. NSRect newInspectorFrame = NSMakeRect(0, 0, self.frame.size.width, 120);
    12. [expandInspectorAnimationDict setObject:[NSValue valueWithRect:newInspectorFrame] forKey:NSViewAnimationEndFrameKey];
    13. NSViewAnimation *expandAnimation = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray arrayWithObjects:expandInspectorAnimationDict, expandMainAnimationDict, nil]];
    14. [expandAnimation setDuration:0.25f];
    15. [expandAnimation setAnimationBlockingMode:NSAnimationBlocking];
    16. [expandAnimation startAnimation];
    17. }
    Alles anzeigen
  • Bedeutet das, dass man teilweise fertige Programme nochmal umschreiben darf ? Wenn Sie nicht dokumentiert sind: Wie bitte soll man dann so etwas lernen ?

    Ich bin nämlich ernsthaft am überlegen auf eine andere Programmiersprache zu wechseln. Den vor allem für den Windows Bereich gibt es mehr Literatur und größere Communities.
  • das hat nichts mit der programmiersprache zu tun sondern einfach damit dass es apple nicht dokumentiert hat. es kann also in 10.11.x noch so sein wie du es grade festgestellt hast und in 10.12 eventuell auch noch, dann aber irgendwann nicht mehr genau so funktionieren wie es grade tut (weil eben nicht dokumentiert).

    hat wie gesagt nichts mit der programmiersprache zu tun...
  • Und wenn ich diesen "Slide" Effekt haben will. In allen meinen Programmen und es anscheinenden nicht dokumentiert ist. Was mache ich dann ?

    Weil entweder ich verstehe Objective C falsch, oder ich bringe mir das falsch bei , aber mir erscheint das alles sehr sehr kompliziert.
    Entweder jede Klasse hat Besonderheiten oder irgendwelche Befehle werden nicht richtig verarbeitet. Vieles kann man sich doch nur über Versuch und Irrtum beibringen oder ?