Mac开发-NSAnimation

2019-07-15  本文已影响0人  只爱随便看看

NSAnimation可以实现简单的视图动画。

#define ANIMATION_TIME              0.5
#define ANIMATION_MASK_COUNT        10
{
    NSAnimation*_theAnimForColse;
}
// 初始化动画,设置时间
    _theAnimForColse = [[NSAnimation alloc] initWithDuration:ANIMATION_TIME animationCurve:NSAnimationEaseOut];
    _theAnimForColse.delegate = self;
    // 设置阻塞模式,异步不阻塞
    [_theAnimForColse setAnimationBlockingMode:NSAnimationNonblocking];
    // 设置多个触发点 (0.0-1.0)
   for(int i = 0; i < ANIMATION_MASK_COUNT; i++)
    {
        [_theAnimForColseaddProgressMark: i * (1.0/ANIMATION_MASK_COUNT)];
    }
    [_theAnimForColse startAnimation];

相关NSAnimation代理

//根据上面设置的触发点,做一些操作

- (void)animation:(NSAnimation*)animation didReachProgressMark:(NSAnimationProgress)progress
{
    if(animation ==_theAnimForColse) {
            floatchangeAlpha = (self.outstandAlpha* (1.0- progress));
            self.window.contentView.alphaValue= changeAlpha; //改变透明度
    }
}

// 动画结束后

- (void)animationDidEnd:(NSAnimation*)animation
{
    if(animation ==_theAnimForColse) {
        [self closeWindow]; //关闭Window
    }
}
上一篇 下一篇

猜你喜欢

热点阅读