0

我在标签和文本字段的动画方面遇到问题。标签只是消失,文本字段不做任何事情。我不知道为什么,但是按钮我没有问题。想想错过了什么真的很愚蠢。好吧,这是 ai 为标签所做的尝试:

UILabel *label = (UILabel*)[self.view viewWithTag:1];
[UIView animateWithDuration:1 animations:^{label.frame = CGRectMake(0,0,1,1);}];

对于文本字段:

UITextField *box = (UITextField*)[self.view viewWithTag:1];
[UIView animateWithDuration:1 animations:^{box.frame = CGRectMake(0,0,1,1);}];

我错过了什么?

4

1 回答 1

2

CGRectMake(0,0,1,1)将是一个非常小的盒子。它们并没有消失,而是将它们全部塞入一个像素中。尝试一些更合理的东西CGRectMake(0,0,100,50),看看是否有效。

CGRectMake定义为:

CGRect CGRectMake (
   CGFloat x,
   CGFloat y,
   CGFloat width,
   CGFloat height
);

所以你将宽度和高度设置为1。

如果你只想移动中心而不调整大小,试试这个。

[UIView animateWithDuration:1 animations:^{label.center = CGPointMake(x,y);}];

其中 x 和 y 是新中心的坐标。

于 2012-08-03T14:37:14.663 回答