您的位置:首页 > 移动开发 > IOS开发

iOS每日一记之——————键盘被挡 自动试图上滚

2015-10-15 18:53 387 查看
键盘覆盖输入框

当键盘调出时将输入框覆盖时,可以用下方法:

- (BOOL)textFieldShouldBeginEditing:(UITextField *)textField{

[self.view setFrame:CGRectMake(0, -100, 320, 480) ];

return YES;

}

- (BOOL)textFieldShouldEndEditing:(UITextField *)textField{

[self.view setFrame:CGRectMake(0, 0, 320, 480)];return YES;

}

当准备输入时,将视图的位置上调 100,这样键盘就不能覆盖到输入框。

当依赖注入方法不好使时,可以在 AppDelegate
内申明一个全局的控制器实例_anotherViewController,在另一个需要使用_anotherViewController
的地方定义以下委托方法,使用共享的 UIApplication
实例来获取该委托的引用

SomeAppDelegate *appDelegate = (SomeAppDelegate *)[[UIApplication sharedApplication]delegate];

_anotherViewController = appDelegate._anotherViewController;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: