cocoa : cocoa 中的哪个方法与 animateWithDuration:animations:completion: 相同?

标签 cocoa

我可以使用 mac os cocoa 中的 animator 实现动画,例如

[[view animator] setFrame:newFrame];

但我的问题是我必须对一些属于 View 属性的点进行动画处理。我可以像下面的 iPhone 代码一样做到这一点:

[UIView animateWithDuration:0.3 animations:^{
                                for (Point point in self.points) {
                                    point.x += 10;
                                }
                           } completion:^(BOOL finished) {

                                }];
                            }];

我想知道如何在 mac ox cocoa 中做到这一点?

最佳答案

通常对于 NSView 动画,您必须覆盖动画师使用的标准动画。

CABasicAnimation* animation = [CABasicAnimation animation];
animation.delegate = yourDelegate;
NSDictionary *animations = [NSDictionary dictionaryWithObjectsAndKeys:animation,@"frameSize",nil];
[view setAnimations:animations];

动画的关键是您想要设置动画的属性。

如果您不需要委托(delegate),您可以使用这样的代码:

[CATransaction begin];
[CATransaction setAnimationDuration:0.5];
[CATransaction setAnimationTimingFunction:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseOut]];
[[view animator] setFrameOrigin:origin];
[CATransaction commit];

如果您需要更复杂的动画,您可以创建一个覆盖窗口,其中包含托管内容 View 的图层,并使用内部 View 屏幕截图对图层进行动画处理。

关于 cocoa : cocoa 中的哪个方法与 animateWithDuration:animations:completion: 相同?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/12002697/

相关文章:

Swift 不绘制图表(XYPieChart)

cocoa - NSOutlineView拖动图片

iphone - 'bezierPathWithOvalInRect' 错误的参数 1 的类型不兼容

objective-c - 如何使用 NSArrayController 对 NSTableView 中的行重新排序

objective-c - 创建一个不是警告消息的工作表

iphone - 如何从 Cell 中获取 UITableViewCell indexPath?

xcode - 如何将 2 个 NSTextView 垂直对齐并在其间留有空间,并使用自动布局使容器 View 相应调整大小

cocoa - 在属性更改时强制重绘自定义 cocoa 控件

objective-c - 如何从 NSCollectionView 中检索 NSCollectionViewItems

iphone - 如何在页面 View Controller 的 ModelController.m 中构建数据源的方法内实现 "Cancel"按钮