textFieldDidBeginEditing 开始编辑 。
textFieldDidEndEditing 结束编辑。
这两个里面分别用
//ImageView* textimageview
textImageView.image = [[UIImage imageNamed:@"name_blue"] resizableImageWithCapInsets:UIEdgeInsetsMake(0, 33, 0, 10)];
//图片名换下 , 这样 在填写Textfiled时跟结束编辑时的 图片样式不一样 ,这样组合 就可以让人感觉 是Textfiled里面有个图片一样 。
对于textfile 在输入的时候 被覆盖时 , 可以选择将textfiled 向上移。
这个可以参考 :
http://blog.csdn.net/wbw1985/article/details/7623699
这种移动Textfiled的效果不是很好看,可以试着移动整个view 。 最好是配上动画效果。 可以参考以下代码 。
//视图上移的方法
- (void) animateTextField: (UITextField *) textField up: (BOOL) up
{
//设置视图上移的距离,单位像素
const int movementDistance = 30; // tweak as needed
//三目运算,判定是否需要上移视图或者不变
int movement = (up ? -movementDistance : movementDistance);
//设置动画的名字
[UIView beginAnimations: @"Animation" context: nil];
//设置动画的开始移动位置
[UIView setAnimationBeginsFromCurrentState: YES];
//设置动画的间隔时间
[UIView setAnimationDuration: 0.20];
//设置视图移动的位移
self.view.frame = CGRectOffset(self.view.frame, 0,
movement);
//设置动画结束
[UIView commitAnimations];
}
调用的时候就是 [self animateTextField: textField up: NO];
[self animateTextField: textField up: YES];
对于 输入完毕后 键盘消失 , 可以使用
- (void)touchesBegan:(NSSet *)touches withEvent:(UIEvent *)event
{
[self.view endEditing:YES];
}
2、获取windows的代码
UIWindow *window = [[UIApplication sharedApplication].windows objectAtIndex:0];
3、