开发者

UIButton animation not working properly

See the commented code below. Why does the UIButton act differently than the 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

Please try!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜