0

我想在按下时改变按钮的位置,它应该再次移动到下方并在按住时重新开始,请告诉我该怎么办?

textField = [[UITextField alloc] initWithFrame:CGRectMake(76, ([txtFieldArray count] * 30), 191, 25)];
[textField setBorderStyle:UITextBorderStyleLine];
textField.font = [UIFont systemFontOfSize:20];
textField.placeholder = @"Enter text";
textField.autocorrectionType = UITextAutocorrectionTypeNo;
textField.keyboardType = UIKeyboardTypeDefault;
textField.returnKeyType = UIReturnKeyDone;
textField.clearButtonMode = UITextFieldViewModeWhileEditing;
textField.contentVerticalAlignment = UIControlContentVerticalAlignmentCenter;
textField.delegate = self;
[myScrollview addSubview:textField];
[txtFieldArray addObject:textField];

CGRect frame = bottomView.frame;
frame.origin.y += textField.frame.size.height + 5;

bottomView.frame = frame;
textField.hidden = NO;
4

4 回答 4

0

在创建 UIButton 并像 UITextField 一样设置它的框架后,你应该使用按钮的setFrame:方法来改变它的位置。

如果你想用按钮改变位置,首先创建一个-(IBAction *)buttonPressed:(id)sender方法并在其中设置按钮的新位置。[button addTarget:self action:@selector(buttonPressed:) forControlEvents:UIControlEventTouchUpInside]然后在创建按钮的位置之后添加方法。

于 2013-04-11T09:54:17.640 回答
0

您可以将标签分配给按钮

UIButton *btn=[UIButton buttonWithType:UIButtonTypeCustom];
[btn setTag:100];
[btn addTarget:self action:@selector(moveButtonDown) forControlEvents:UIControlEventTouchUpInside];

并且每当单击按钮时,可以通过获取按钮的引用来更改按钮的框架。在下面的代码中,我将按钮向下移动了 20 个像素。您可以将此值更改为您想要的任何值。

 -(void)moveButtonDown
{
    UIButton *btn=(UIButton *)[self.view viewWithTag:100];
    float y=btn.frame.origin.y;
    y+=20;
    [btn setFrame:CGRectMake(btn.frame.origin.x, y, btn.frame.size.width, btn.frame.size.height)];
}
于 2013-04-11T10:08:50.290 回答
0

仅在您描述的片段中给出按钮的框架。

例如,

<button_object>.frame =
CGRectMake(textField.frame.origin.x,textField.frame.origin.y +
x,textField.size.width,textField.size.height);


Where X = the difference upto which you want to add the button after
textfield. For ex, 44 or 50 or so on..

享受编程!

于 2013-04-11T10:04:39.713 回答
0

您必须通过以下方式修改代码:

CGRect frame = bottomView.frame;
frame.origin.y += (tField.frame.origin.y+textField.frame.size.height + 5);

bottomView.frame = frame;
textField.hidden = NO;
于 2013-06-08T09:59:41.990 回答