我如何摆脱这些警告
“警告:'UIButton' 可能不会响应'-setPosition:'
和
“警告:'UIButton' 可能不会响应 '-addAnimation:forKey'
我在这里得到它们:
- (void)monBtnIn {
[monButton setPosition:CGPointMake(113.5,256.5)];
[monButton addAnimation:[self monInAnimation]
forKey:@"position"];
}
一切构建和加载都很好,但我不喜欢警告。我认为这与它是 UIButton 而不是 CALayer 的事实有关。
那么,如何使 UIButton 工作?
.h 文件
IBOutlet UIButton *monButton;
这是 KeyFrameAnimation - 它创建了一个“有弹性的”动画来解决。
- (CAAnimation*)monInAnimation {
CGMutablePathRef path = CGPathCreateMutable();
CGPathMoveToPoint(path,NULL,113,520);
CGPathAddLineToPoint(path, NULL, 113.5, 286);
CGPathAddLineToPoint(path, NULL, 113.5, 242);
CGPathAddLineToPoint(path, NULL, 113.5, 270);
CGPathAddLineToPoint(path, NULL, 113.5, 250);
CGPathAddLineToPoint(path, NULL, 113.5, 262);
CGPathAddLineToPoint(path, NULL, 113.5, 254);
CGPathAddLineToPoint(path, NULL, 113.5, 258);
CGPathAddLineToPoint(path, NULL, 113.5, 256.5);
CAKeyframeAnimation *
animation = [CAKeyframeAnimation
animationWithKeyPath:@"position"];
[animation setPath:path];
[animation setDuration:1.5];
NSArray *arr = [NSArray arrayWithObjects:[NSNumber numberWithFloat:0.0],
[NSNumber numberWithFloat:0.12],
[NSNumber numberWithFloat:0.24],
[NSNumber numberWithFloat:0.36],
[NSNumber numberWithFloat:0.48],
[NSNumber numberWithFloat:0.60],
[NSNumber numberWithFloat:0.72],
[NSNumber numberWithFloat:0.84],
[NSNumber numberWithFloat:1.0],nil];
[animation setKeyTimes:arr];
[animation setTimingFunctions:[NSArray arrayWithObjects:[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseIn],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut],
[CAMediaTimingFunction functionWithName:kCAMediaTimingFunctionEaseInEaseOut], nil]];
//[animation setAutoreverses:YES];
CFRelease(path);
return animation;
}
非常感谢您的帮助!