0

我目前有一个视图,其中我有一个滚动视图。在那个滚动视图上,我有一个按钮和一个 UITableView。

在某些条件下,我想将这两件事向上移动。我目前正在这样做:

    tempFrame = [addressTableView frame];
    tempFrame.origin.x = 0.0;
    tempFrame.origin.y = 2.0;
    tempFrame.size.width = 320.0;
    tempFrame.size.height = 103.0;
    [addressTableView setFrame:tempFrame];        
   // [self.scrollView addSubview:self.addressTableView]; (does not do anything)

    tempFrame = [buttonContinue frame];
    tempFrame.origin.x = 20.0;
    tempFrame.origin.y = 40.0;
    tempFrame.size.width = 150.0;
    tempFrame.size.height = 25.0;
    [buttonContinue setFrame:tempFrame];
   // [self.scrollView addSubview:self.buttonContinue]; (does not do anything)

此方法适用于没有 scrollView 的视图。

任何有关如何正确移动滚动视图中的对象的提示将不胜感激。

谢谢。

4

4 回答 4

2

如果我理解您的问题,我认为您应该在文件检查器中取消选中此特定 ViewController 的“自动布局”属性。我有同样的问题,通过取消选中自动布局,我的问题得到了解决。可能这将有助于解决您的问题。

祝你好运 !!

于 2013-08-21T18:49:43.817 回答
1

如果您只是移动它们,而不是调整大小,请尝试使用 CGAffineTransform 移动按钮。(您也可以通过连接 CGscale 和 CGtranslate 来调整大小)。

因此,对于您的按钮,它将非常接近:

buttonContinue.transform = CGAffineTransformMakeTranslation(20,40);

这会将您的按钮向右移动 20 像素,向下移动 40 像素。

要稍后将其移回,只需调用:

buttonContinue.transform = CGAffineTransformIdentity;

另外,顺便说一句,您可以使用一行创建一个新框架,而不是上面的四行,例如:

buttonContinue.frame = CGRectMake(20, 40, 150, 25);
于 2013-08-21T18:22:07.890 回答
0

移动按钮的最佳方式

 [btn addTarget:self action:@selector(pointMoved:withEvent:) forControlEvents:UIControlEventTouchDragInside];
-(IBAction) pointMoved:(id) sender withEvent:(UIEvent *) event
{
  CGPoint point = [[[event allTouches] anyObject] locationInView:self]; //here you can give scrollview
  UIControl *control = sender;
  control.center = point;
}
于 2013-08-22T05:18:09.770 回答
0

试试这个,

[addressTableView setFrame:CGRectMake(0,2,320,103)];        
[buttonContinue setFrame:CGRectMake(20,40,150,25)];

如果这不起作用,那么您的元素addressTableViewbuttonContinue的参考存在问题。如果它们不在您的滚动视图中,请使用

[self.scrollView addSubview:addressTableView];
[self.scrollView addSubview:buttonContinue];

确保您的 scrollView 变量与其在 IB 上的元素相关联。

于 2013-08-21T19:52:12.280 回答