开发者

UIView beginanimations: subview shall not animate

开发者 https://www.devze.com 2023-01-12 14:22 出处:网络
Hi I have a UIView to which I add a UIButton in its initWithFrame: method like this: UIButton * dropB = [UIButton buttonWithType:UIButtonTypeRoundedRect];

Hi I have a UIView to which I add a UIButton in its initWithFrame: method like this:

UIButton * dropB = [UIButton buttonWithType:UIButtonTypeRoundedRect];
dropB.frame = CGRectMake(190, 22, 52, 22);
dropB.backgroundColor = [UIColor clearColor];
dropB.titleLabel.font = [UIFont fontWithName:@"Helvetica-Bold" size:11];
[dropB setTitle:@"DROP" forState:UIControlStateNormal];
[dropB addTarget:viewController 
          action:@selector(dropSelectedObject)
forControlEvents:UIControlEventTouchUpInside];

[self addSubview:dropB];

Then, as I try to animate the view with a resizing like this:

[UIView beginAnimations:@"MoveIt" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.dropButton.cente开发者_StackOverflow社区r = CGPointMake(self.dropButton.center.x + 80, self.dropButton.center.y -10);
self.frame = CGRectMake(0, 0, WIDTH, HEIGHT); 
self.center = CGPointMake(CENTER_X, CENTER_Y);
[UIView commitAnimations];

The button only gets translated to a new position which is the previous one (the original coordinates were relative to the view i guess). How can I make it translate to the point i specify?


Ok it was pretty simple (and stupid).

Since I needed the UIButton to remain at a fixed height I had to specify what space was 'flexible' while resizing. This can be done using the autoresizingMask property of an UIView this way:

dropB.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleBottomMargin;

and not calling anithing among the animation instructions

0

精彩评论

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

关注公众号