带有导航栏的控制器上键盘挡住输入框的解决方案

   本人用 textFile的代理做时,不知道是不是因为有导航栏的原因,导致输入框,控制器的view都会抖一下,虽然有效    果了,但是这么大的BUG还是不能忍。
   本文采用的是代理和点击事件

 [field addTarget:self action:@selector(textFieldDidBeginEditing:) forControlEvents:UIControlEventEditingDidBegin];

    [field addTarget:self action:@selector(textFieldDidEndEditing:) forControlEvents:UIControlEventEditingDidEnd];

    

   

-(void)textFieldDidBeginEditing:(UITextField *)textField{

    if (iPhone4 || iPhone5) {

        

    

    //开始编辑时,整体上移

       if (textField.tag==3) {

          [self moveView:-40];

        }

    }

}

-(void)textFieldDidEndEditing:(UITextField *)textField{

    

    if (iPhone4 || iPhone5) {

        //结束编辑时,整体下移

       if (textField.tag==3) {

          [self moveView:40];

        }

        

    }

}

-(void)moveView:(float)move{

   

    CGRect frame = self.view.frame;

    frame.origin.y +=move;

    //self.view.frame = frame;

    [UIView beginAnimations:@"ResizeView" context:nil];

    self.view.frame = frame;

    [UIView commitAnimations];//设置调整界面的动画效果

    

    

}



#pragma mark UITextFiled的代理方法,为的是输入后点击return能让键盘退下去

- (BOOL)textFieldShouldReturn:(UITextField *)textField

{

    [textField endEditing:YES];

    [textField resignFirstResponder];

    return YES;



}



  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
旅游网站导航控制器的关键代码会根据具体实现方式不同而有所不同,下面是一个简单的示例: ```swift class NavigationBarViewController: UIViewController { // 导航控件 let searchBar = UISearchBar() let segmentedControl = UISegmentedControl(items: ["国内游", "出境游", "周边游"]) let filterButton = UIButton(type: .system) override func viewDidLoad() { super.viewDidLoad() // 添加导航控件 searchBar.placeholder = "搜索旅游目的地" navigationItem.titleView = searchBar segmentedControl.selectedSegmentIndex = 0 navigationItem.titleView = segmentedControl filterButton.setTitle("筛选", for: .normal) navigationItem.rightBarButtonItem = UIBarButtonItem(customView: filterButton) // 设置导航外观 navigationController?.navigationBar.tintColor = .white navigationController?.navigationBar.barTintColor = .blue navigationController?.navigationBar.isTranslucent = false navigationController?.navigationBar.titleTextAttributes = [NSAttributedString.Key.foregroundColor: UIColor.white] } // 搜索按钮点击事件 func searchBarSearchButtonClicked(_ searchBar: UISearchBar) { // 处理搜索逻辑 } // 分段控件点击事件 @objc func segmentedControlValueChanged(_ segmentedControl: UISegmentedControl) { // 处理分段逻辑 } // 筛选按钮点击事件 @objc func filterButtonTapped(_ sender: UIButton) { // 处理筛选逻辑 } } ``` 这个示例中,`NavigationBarViewController` 是一个 UIViewController 子类,用于管理导航控件。在 `viewDidLoad()` 方法中,我们添加了三个控件:`searchBar`、`segmentedControl` 和 `filterButton`。然后,我们还对导航外观进行了一些设置。最后,我们还添加了三个事件处理方法:`searchBarSearchButtonClicked(_:)`、`segmentedControlValueChanged(_:)` 和 `filterButtonTapped(_:)`。这些方法会根据不同的控件事件来处理对应的业务逻辑。
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值