我正在尝试学习如何在 objc 中使用 UIViewPropertyAnimator。我用一个名为“blueBox”的对象制作了一个简单的测试应用程序。我想改变 blueBox 的属性。
我在@implementation 之外声明'animator' ... @end:
UIViewPropertyAnimator *animator;
然后像这样定义它:
- (void)viewDidLoad {
[super viewDidLoad];
CGRect newFrame = CGRectMake(150.0, 350.0, 100.0, 150.0);
animator = [[UIViewPropertyAnimator alloc]
initWithDuration:2.0
curve:UIViewAnimationCurveLinear
animations:^(void){
self.blueBox.frame = newFrame;
self.blueBox.backgroundColor = [UIColor redColor];
}];
}
当我想使用它时,我会写:
animator.startAnimation;
它按预期工作(更改对象的颜色和框架),但在 'animator.startAnimation;' 上有警告 上面写着“未使用的属性访问结果 - 不应将吸气剂用于副作用”。指的是什么属性访问结果?我应该怎么写这样我就不会收到警告?