gpt4 book ai didi

macos - NSImageView 动画

转载 作者:行者123 更新时间:2023-12-03 16:13:11 25 4
gpt4 key购买 nike

我是Mac开发新手,我们有类似的方法吗 imagev = [NSArray arrayWithObjects

我需要一些类似于我们在 iOS 中所做的事情想要在 mac 中做的事情,

imageVie.animationImages = [NSArray arrayWithObjects:
[UIImage imageNamed:@"1.png"],[UIImage imageNamed:@"2.png"],
[UIImage imageNamed:@"3.png"],[UIImage imageNamed:@"4.png"],
[UIImage imageNamed:@"5.png"],[UIImage imageNamed:@"6.png"],
[UIImage imageNamed:@"7.png"] ,nil];

在 iPhone 中,我如何制作动画

问候

最佳答案

我发现有人使用 Core Animation approach to this issue这对我来说已经足够近了。我稍微修改了一下。您需要@import QuartzCore;

- (void)awakeFromNib
{
CALayer *layer = [CALayer layer];
NSMutableArray *spinnerImages = [NSMutableArray arrayWithCapacity:30u];
for (NSUInteger i = 0; i < 30; ++i)
{
NSString *imageName = [NSString stringWithFormat:@"spinner%@", @(i)];
[spinnerImages addObject:[NSImage imageNamed:imageName]];
}
self.spinnerImages = spinnerImages;
layer.frame = self.imageView.bounds;
[self.imageView setLayer:layer]; // This view is just a container for the layer. Its frame can be managed by a xib.
self.imageView.wantsLayer = YES;

self.spinnerLayer = layer;
}

然后你可以像这样设置动画:

- (void)stopAnimating
{
if ([self.layer.animationKeys containsObject:kAnimationKey])
{
[self.layer removeAnimationForKey:kAnimationKey];
}
}

- (void)startAnimating
{
if ([self.layer.animationKeys containsObject:kAnimationKey])
{
return;
}
CAKeyframeAnimation *animation = [CAKeyframeAnimation animationWithKeyPath:kAnimationKey];
[animation setCalculationMode:kCAAnimationDiscrete];
[animation setDuration:1.0f];
[animation setRepeatCount:HUGE_VALF];
[animation setValues:self.spinnerImages];
[self.spinnerLayer addAnimation:animation forKey:kAnimationKey];
}

关于macos - NSImageView 动画,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/14064328/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com