您好我有一个UIView,我在其initWithFrame:
方法中添加了一个UIButton,如下所示:
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];
然后,当我尝试使用这样的大小调整为视图设置动画时:
[UIView beginAnimations:@"MoveIt" context:nil];
[UIView setAnimationDuration:0.5];
[UIView setAnimationBeginsFromCurrentState:YES];
self.dropButton.center = 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];
按钮仅转换到新位置(前一个位置)(原始坐标相对于我猜的视图)。如何将其转换为我指定的点?
答案 0 :(得分:0)
好吧,这很简单(也很愚蠢)。
由于我需要将UIButton保持在固定的高度,因此我必须在调整大小时指定哪些空间是“灵活的”。这可以通过这种方式使用UIView的autoresizingMask
属性来完成:
dropB.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleBottomMargin;
并且不在动画指令中调用anithing