Я пытаюсь показать список комментариев, используя subview. Я добавил subview в self.view, и я добавил tableview к нему, чтобы показать список комментариев. теперь я хочу, чтобы пользователь добавил комментарий, я попытался добавить еще один подзаголовок к первому с текстовым полем и кнопкой в нижней части экрана, но теперь я хочу переместить это представление вверх, когда клавиатура появится, а затем вернется внизу при отправке комментария, я попытался изменить рамки commentView, когда textfieldBeginEditing, но это не меняется! мой способ не работает, есть ли у вас идея делать то, что я хочу?Перемещение subview при появлении клавиатуры
благодаря
это то, что я делаю, вид называется MyView является то, что я хочу двигаться вверх:
CGRect screenRect = [[UIScreen mainScreen] bounds];
CGFloat screenWidth = screenRect.size.width;
CGFloat screenHeight = screenRect.size.height;
// notification button
myView = [[UIScrollView alloc] initWithFrame:CGRectMake(0, 0, screenWidth,screenHeight)];
[myView setBackgroundColor:[UIColor whiteColor]];
[myView setTag:2013];
commentView = [[UIView alloc] initWithFrame:CGRectMake(0,screenHeight-70,screenWidth,70)];
[commentView setBackgroundColor:[UIColor redColor]];
// [commentView viewWithTag:2031];
table = [[UITableView alloc] initWithFrame:CGRectMake(0,50, screenWidth, screenHeight-100)];;
table.dataSource=self;
table.delegate=self;
UILabel *currentdate = [[UILabel alloc] initWithFrame:CGRectMake(0,10,screenWidth-40,50)];
currentdate.backgroundColor = [UIColor clearColor];
[currentdate setTextColor: [UIColor blueColor]];
[currentdate setText:@"Comments"];
currentdate.textAlignment= UITextAlignmentCenter;
currentdate.font = [UIFont fontWithName:@"Helvetica" size:20.0];
commentFeild = [[UITextField alloc] initWithFrame:CGRectMake(60,10,screenWidth-60,30)];
[email protected]"add comment";
commentFeild.backgroundColor = [UIColor whiteColor];
[commentFeild setTextColor: [UIColor blueColor]];
commentFeild.textAlignment= UITextAlignmentRight;
commentFeild.font = [UIFont fontWithName:@"Helvetica" size:15.0];
[commentFeild.layer setCornerRadius:14.0f];
[commentFeild setTag:2113];
//[commentFeild setDelegate:self];
UIButton *doneBtn=[UIButton buttonWithType:UIButtonTypeRoundedRect];
doneBtn.frame = CGRectMake(screenWidth-45, 10,40, 30);
doneBtn.backgroundColor = [ UIColor clearColor];
[doneBtn setTitle:@"done" forState:UIControlStateNormal];
[doneBtn setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[doneBtn addTarget:self action:@selector(hide) forControlEvents:UIControlEventTouchUpInside];
UIButton *add=[UIButton buttonWithType:UIButtonTypeRoundedRect];
add.frame = CGRectMake(5,10,50,30);
add.backgroundColor = [ UIColor clearColor];
[add setTitle:@"add" forState:UIControlStateNormal];
[add setTitleColor:[UIColor blueColor] forState:UIControlStateNormal];
[add addTarget:self action:@selector(addComment) forControlEvents:UIControlEventTouchUpInside];
if(![taskObject.status isEqualToString:@"doneTask"])
{
[commentView addSubview:commentFeild];
[commentView addSubview:add];
}
[myView addSubview:doneBtn];
[myView addSubview:currentdate];
[myView addSubview:table];
[myView addSubview:commentView];
[self.view addSubview:myView];
вставить код, который не работает для вас –
Если вы обеспечиваете эту точку зрения с помощью представления таблицы (UITableViewCell), а не добавление в качестве subview это будет легко для вас. Tableview уже занимается настройкой кадра, добавляя слушателей клавиатуры. Тем не менее, если вы хотите добавить только подвью, вам нужно добавить scrollview, соединить соответствующие делегаты и добавить представление комментариев в подвью. В текстовом файле начнется редактирование, вы должны соответственно установить смещение содержимого подвью. Надеюсь это поможет. –
добавление текстового поля в представление таблицы показывает его в последней строке и о необходимости его отображения. – etab