【问题标题】:How can I make the NSWindow setFrame: .. animated:YES] function animated down instead of up?如何使 NSWindow setFrame: .. animated:YES] 函数向下而不是向上动画?
【发布时间】:2011-01-09 23:28:40
【问题描述】:

当我调用我的 [window setFrame: frame animated:YES] 来放大窗口时,它工作得很好,但它会动画化并且它位于状态栏的后面。我怎样才能让窗口动画下来呢?

【问题讨论】:

    标签: objective-c cocoa nswindow


    【解决方案1】:

    只需减少 y 坐标与增加高度的距离相同。

    CGFloat amountToIncreaseWidth = 100, amountToIncreaseHeight = 100;
    NSRect oldFrame = [window frame];
    oldFrame.size.width += amountToIncreaseWidth;
    oldFrame.size.height += amountToIncreaseHeight;
    oldFrame.origin.y -= amountToIncreaseHeight;
    [window setFrame:oldFrame animated:YES];
    

    【讨论】:

    • 这就是我最终要做的事情,理想情况下我想用内置的 animate 函数做一些事情,但我看不到这样做的方法。
    • 这使用了内置动画。
    【解决方案2】:

    我找不到一个简单的方法来做到这一点,所以我编写了一个动画函数,它可以调整窗口大小并同时移动它,从而使它看起来像动画一样。

    - (IBAction)startAnimations:(id)sender{
    
        NSViewAnimation *theAnim;
        NSRect firstViewFrame;
        NSRect newViewFrame;
        NSMutableDictionary* firstViewDict;
    
        {
            firstViewDict = [NSMutableDictionary dictionaryWithCapacity:3];
            firstViewFrame = [window frame];
            [firstViewDict setObject:window forKey:NSViewAnimationTargetKey];
    
            [firstViewDict setObject:[NSValue valueWithRect:firstViewFrame]
                              forKey:NSViewAnimationStartFrameKey];
    
            newViewFrame = firstViewFrame;
    
            newViewFrame.size.height += 100;
            newViewFrame.origin.y -= 100;
    
            [firstViewDict setObject:[NSValue valueWithRect:newViewFrame]
                              forKey:NSViewAnimationEndFrameKey];
        }
    
        theAnim = [[NSViewAnimation alloc] initWithViewAnimations:[NSArray
                                                                   arrayWithObjects:firstViewDict, nil]];
    
        [theAnim setDuration:1.0]; 
        [theAnim startAnimation];
    
        [theAnim release];
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2016-06-15
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2016-08-08
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多