gpt4 book ai didi

iphone - 如何修复此 "may not respond"警告?

转载 作者:行者123 更新时间:2023-12-03 20:37:17 26 4
gpt4 key购买 nike

如何消除这些警告

“警告:‘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;

}

预先非常感谢您的帮助!

最佳答案

您是否尝试过将图层本身作为目标

[monButton.layer setPosition:CGPointMake(113.5,256.5)];
[monButton.layer addAnimation:[self monInAnimation]
forKey:@"position"];

关于iphone - 如何修复此 "may not respond"警告?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/1994555/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com