可可焦点环颜色动画 [英] Cocoa focus ring color animation

查看:131
本文介绍了可可焦点环颜色动画的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想使用对焦环动画作为字段中不正确数据的指示器。所以我发送becomeFirstResponder:到字段,并希望聚焦环从红色淡出到默认颜色。

I want to use a focus ring animation as an indicator of incorrect data in field. So I'm sending becomeFirstResponder: to field and want focus ring to fade from red to default color.

我与Core Animation搏斗,但仍然没有找到任何方式去做吧。可能吗?

I'm wrestling with Core Animation but still have not found any way to do it. Is it possible?

推荐答案

我不知道这个策略是否遵循HIG,表示字段旁边的字段的持久图标不会在字段旁边生效,但是不应太难以获得您所寻求的效果。

I'm not sure if this strategy follows the HIG, its often more common to do something like display a persistent icon indicating a field doesn't validate next to the field, but it shouldn't be too hard to get the effect you're seeking.

它可能更容易使用简单的 NSAnimation 这里,而不是使用Core Animation。
绘制对焦环的标准代码通常如下:

It might be easier to use a simple NSAnimation here instead of using Core Animation. The standard code for drawing a focus ring generally goes something like the following:

[NSGraphicsContext saveGraphicsState];
NSSetFocusRingStyle(NSFocusRingOnly);
[[NSColor clearColor] set];
[[NSBezierPath bezierPathWithRect:focusRect] fill];
[NSGraphicsContext restoreGraphicsState];

此代码将在控件的自定义子类中的drawRect:方法中实现。

This code would be implemented in the drawRect: method in custom subclass of your control.

为了绘制一个自定义彩色聚焦环,你需要自己绘制矩形,并且不能从NSSetFocusRingStyle函数中受益。颜色将被驱动脱离NSAnimation,这也将设置控制重新绘制自己。因为你没有使用Cocoa的设施来绘制聚焦环,你还可能需要插入视图的内容,这样你就有空间绘制圆环。

In order to draw a custom colored focus ring, you'll need to draw the rectangle yourself, and won't be able to benefit from the NSSetFocusRingStyle function. The color would be driven off of the NSAnimation, which would also set the control to repaint itself. Because you're not using Cocoa's facilities to draw the focus ring, you'll also probably need to inset the content of your view so you'll have space to draw the ring.

有关NSAnimations的详情,请参阅 Cocoa的动画编程指南

More information regarding NSAnimations is available in the Animation Programming Guide for Cocoa

这篇关于可可焦点环颜色动画的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆