【发布时间】:2014-12-11 12:14:17
【问题描述】:
我想在 WatchKit 中制作一个带有动画的按钮,但似乎我找不到修改 WKInterfaceButton 或将图像拖到故事板中的按钮的方法。任何帮助表示赞赏。
【问题讨论】:
标签: ios objective-c xcode watchkit
我想在 WatchKit 中制作一个带有动画的按钮,但似乎我找不到修改 WKInterfaceButton 或将图像拖到故事板中的按钮的方法。任何帮助表示赞赏。
【问题讨论】:
标签: ios objective-c xcode watchkit
经过一番研究,我找到了解决方案,它非常简单但很容易被忽略:)
首先,将一个按钮拖到故事板中创建的场景中。
其次,选择按钮,将其属性content从Text修改为Group。如果找不到content 属性,请单击屏幕右上角的Attributes Inspector 按钮,它看起来像一个断点按钮或带有条形的向下箭头。
现在您可以控制在您的按钮内创建的组。您需要在控制器代码中添加此WKInterfaceGroup 的引用。这是一个例子:
@interface AAPLButtonDetailController()
@property (weak, nonatomic) IBOutlet WKInterfaceGroup *buttonGroup;
@end
@implementation AAPLButtonDetailController
- (instancetype)init {
self = [super init];
if (self) {
// Initialize variables here.
// Configure interface objects here.
[_buttonGroup setBackgroundImageNamed:@"Bus"];
[_buttonGroup startAnimating];
}
return self;
}
所以按钮动画会在场景初始化后播放。请记住,目前仅支持帧动画,一个动画中的所有帧都应命名为“Bus0.png”、“Bus1.png”....
希望这可以帮助:)
【讨论】:
在我需要控制重复次数或持续时间的情况下,Reck 的帖子对我有用。如果您只是想为按钮启动或停止动画,以下对我有用,其中 twoButton 是 WKInterfaceButton,我有一组图像名称 Bus0@2x.png、Bus1@2x.png 等。
- (void)startButtonAnimating
{
// This works, but can't control repeat counts or duration
[self.twoButton setBackgroundImageNamed:@"Bus"];
// But you can stop after a delay by setting background image nil
[self performSelector:@selector(stopGroupButtonAnimating) withObject:nil afterDelay:1.5];
}
- (void)stopButtonAnimating
{
[self.twoButton setBackgroundImage:nil];
}
【讨论】: