【问题标题】:Moving an UIView when UIButton is pressed按下 UIButton 时移动 UIView
【发布时间】:2011-04-09 07:13:48
【问题描述】:

我的视图层次如下:

BigView
- UIScrollView
  - View 1
  - View 2
  - View 3
- UIView
  - UIButton

现在我想要,当我按下 UIButton 时,BigView(也包括按钮)移动 100px 到顶部(因此 BigView 的某些部分不再可见)并且另一个 UIView 可以免费看到BigView 下的空间。

你有问题吗? :)

我怎样才能做到这一点?

提前致谢!

【问题讨论】:

  • “其中也包括按钮”是什么意思? UIView 只能有一个单亲。
  • 只是按钮在大视图的子视图中。但重要的是,我如何将动画视图移动到顶部,它在顶部被切割,底部有可用空间。

标签: iphone ipad uiview sdk uibutton


【解决方案1】:

斯威夫特 3

  let rect = someView.frame

  self.view1.frame = CGRect(x: view1.frame.midX, y: 400, width: rect.width, height: rect.height)

// 或

 rectHeigh = someView.frame.height
 rectWidth = someView.frame.width

 view1.frame = CGRect(x: view1.frame.midX, y: 400, width: rectWidth, height: rectHeigh)

【讨论】:

    【解决方案2】:

    如果你想要一个即时移动(没有动画),你可以这样做:

    CGRect rect = someView.frame;
    self.someView.frame = CGRectMake(0, 0, rect.size.width, rect.size.height);
    

    【讨论】:

      【解决方案3】:

      只需在点击按钮时调用的方法中做一个 UIView 动画即可:

      [UIView beginAnimations:@"MoveView" context:nil];
      [UIView setAnimationCurve:UIViewAnimationCurveEaseIn];
      [UIView setAnimationDuration:0.5f];
      self.BigView.frame = CGRectMake(newXPoistion, newYPosistion, samewidth, sameheight);
      [UIView commitAnimations];  
      

      这将使 bigview 动画到您提供的新坐标,并且应该移动该视图中的所有内容

      【讨论】:

        猜你喜欢
        • 1970-01-01
        • 2015-03-27
        • 2012-06-26
        • 1970-01-01
        • 2014-04-12
        • 2013-05-08
        • 1970-01-01
        • 2012-07-15
        • 1970-01-01
        相关资源
        最近更新 更多