【问题标题】:UIView beginanimations: subview shall not animateUIView beginanimations:子视图不应动画
【发布时间】:2010-08-18 07:52:23
【问题描述】:

您好,我有一个 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];

按钮只会被转换到一个新位置,即前一个位置(我猜原始坐标是相对于视图的)。我怎样才能把它翻译成我指定的点?

【问题讨论】:

    标签: iphone uiview uibutton beginanimations


    【解决方案1】:

    好的,这很简单(而且很愚蠢)。

    由于我需要 UIButton 保持在固定高度,因此我必须在调整大小时指定哪些空间是“灵活的”。这可以通过这种方式使用 UIView 的 autoresizingMask 属性来完成:

    dropB.autoresizingMask = UIViewAutoresizingFlexibleLeftMargin |UIViewAutoresizingFlexibleBottomMargin;
    

    并且在动画指令中不调用 anithing

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2010-10-26
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2012-01-31
      • 1970-01-01
      相关资源
      最近更新 更多