gpt4 book ai didi

ios - UIButton 动画无法正常工作

转载 作者:行者123 更新时间:2023-11-28 19:24:29 24 4
gpt4 key购买 nike

请参阅下面的注释代码。为什么 UIButton 的行为与 UIView 不同?

//button creation
UIButton *myBtn = [UIButton buttonWithType:UIButtonTypeCustom];
[myBtn setImage:[UIImage imageNamed:@"someImage"] forState:UIControlStateNormal];
self.myButton = myBtn;

...
///in the button target method:

UIView* test = [[UIView alloc] initWithFrame:self.myButton.frame];
test.backgroundColor = [UIColor redColor];
[buttonContainer addSubview:test];

[UIView beginAnimations:@"SomeAnimation" context:nil];
[UIView setAnimationDuration:5];
[UIView setAnimationDelegate:self];
self.myButton.frame = CGRectMake(100,100,200,200); //the position animates smoothly, but the size snaps to 200,200 immediately
//test.frame = CGRectMake(100,100,200,200); //this works perfectly. the position and size both animate smoothly over the 5 seconds.
[UIView commitAnimations];

最佳答案

@implementation UIButton(fixResizeAnimation)

- (void)setFrame:(CGRect)_frame {
[super setFrame:_frame];
for(UIView* v in self.subviews) {
if([v isKindOfClass:[UIImageView class]]) {
[v setFrame:_frame];
}
}
}

@end

请尝试!

关于ios - UIButton 动画无法正常工作,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/5036625/

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